TUTORIAL

Installation of WordPress and Docker with your own local domain

In this article I will show you how to quickly and easily, without additional programs such as XAMPP or WampServer – place WordPress locally with your own local domain. This is possible with Docker, tool which allows to replace virtualization with containerization.

Containerization is a process that allows you to run the indicated applications in separate containers, which are separate instances of the runtime environment. Thanks to this solution, each container has its own memory area, network interface with IP address and disk area.

I have presented more or less what Docker is about, if you want to learn more I invite you to the article:

Docker for programmers, what is it?

Docker Desktop installation for Windows

In our case, we will operate on Windows. If you have Linux the installation is almost the same. Moreover Linux is in my opinion better and faster environment for Docker. In case of this project, which is only about creating WordPress image locally – we will operate on Windows.

We get Docker’s installer and run it on Windows

We are going to go to the site:

https://www.docker.com/products/docker-desktop

We select the system that interests us and download the installer.

We run the installer and install Docker Desktop for Windows.

Here you will find the installation documentation for Windows: https://docs.docker.com/docker-for-windows/install/.

After installation, run Docker Desktop for Windows.

Runrun WordPress with Docker Desktop for Windows

To run WordPress on our local machine with the help of Docker, we will use the solutions contained in the guide:

WordPress Local Development Using Docker Compose.

We are cloning the environment to fire WordPress on Docker

The first step will be to create a folder with our project. We create the folder in a selected location using Command Line:

Inside the folder we execute the command:

In this way, we clone a ready-made WordPress environment to be fired by Docker. You can download it manually by entering the link:https://github.com/kassambara/wordpress-docker-compose

We install WordPress by Docker

Now that we have the basic configuration files cloned, we go to the project folder:

We install our project with a command:

We can go to the WordPress installation on our local machine by going to the address: http://localhost

Private your own local domain – WordPress with Docker

If we would like our website to be fired by our own url, and not by http://localhost as a standard, we need to create and configure an .env file in our project folder accordingly. The second step will be to enter the new hostname in the windows configuration file: hosts

Configure the .env file of the WordPress project

In our wordpress-docker-compose project folder we create a .env file, and inside the file we include the configuration:

Here we can configure the values that will set our WordPress accordingly. We want to change our project url. We will call our domain mywppage.com and add it in values:

Now we can move on to editing the hosts file.

We add a local domain in Windows

Go to the folder C:\Windows\Systems32\drivers\etc and edit the hosts file. It is important to open the file or start Command Line as administrator.

Add the line:

We are now launching our website http://mywppage.com/

wordpress docker wlasna domena

After proper configuration, adding a user and logging in to our new page we get a view of the cockpit of our clean WordPress installation with Docker:

wlasna domena lokalna wordpress

Summary

The Docker theme is a very broad one and often causes many problems for programmers. In this article you have learned how to correctly install CMS WordPress locally using Docker. It was quick and easy to install, but not always so easy. There are more and more complex and complicated configurations of bootable environments, but there are more and more ready-made solutions to make it easier for developers to use Docker.

If you like the article I invite you to visit our list of articles: Useful articles.