First, visit the Docker homepage and look for the Get Docker tab. Then, choose the version you want based on your operating system:
On the next page, you can download the application and then run the installer. This part is very simple – all you need to do is keep moving through the screens and wait until the installation is complete. When it’s done, you’ll need to restart your computer.
Once your system is back up and running, open your command line. On Windows, you can just search for Powershell if you don’t want to install another program. Then, type in docker ps. If you installed Docker successfully, you should see something like this:
A list of your running Docker containers.
That’s a list of the containers currently running on your computer and as you can see, it’s empty. Let’s fix that right away.
Step #2: Set up a container with a WordPress environment
There are two ways to go about this step – you can create a container and set up all the elements you need one by one, or you can do it all in one fell swoop. Naturally, the second route is the smart way to go, so let’s walk through it.
We’re going to use a tool called Docker Compose, which enables you to configure the services you want your container to have and set them up all at once. Start out by opening the command line again and entering these two commands, one after the other:
mkdir wordpress-local && cd wordpress-local
What these commands do is create a directory called wordpress-local on your computer, then add a new file called docker-compose.yml inside that directory.
In order to create your WordPress environment, you’ll need to add some parameters to that file. Using your normal folder tool, find the folder you just created on your computer and open docker-compose.yml using your favorite text editor. Paste the following code snippet into the file:
Save your changes now, and close your editor. What you just did is instruct Docker to set up a new database for WordPress (called my-wpdb) and install the platform itself along with all the other services it needs. We also assigned specific ports and individual passwords, which you can customize by editing the values in the file. With that out of the way, let’s move on to the last step.
Step #3: Get your WordPress container up and running
All that’s left now is to tell Docker to start up your container. To do that, use the following command from within the folder where your docker-compose.yml is located.
docker-compose up -d
Now, sit back and wait for Docker to download and set up all the services you indicated in your docker-compose.yml file. This might take a few minutes, depending on your internet connection.
Once the setup is complete, you’ll be able to access your WordPress site from any browser by entering the ports you set up earlier. In this case, those would be 127.0.0.3:8080:
Local WordPress development using Docker: Finishing up.
All that’s left to do now is follow the regular WordPress setup process in your browser.
Keep in mind that you can set up as many Docker containers as you want, and power them up or down at will using these two commands:
docker-compose up -d