local WordPress development using Docker

Every local website needs an adequate environment to work properly. That typically means setting up a web server, a database, and support for all the languages you’ll need. The problem is that installing all these components can get tricky, and they may not play nice with each other. That’s why it’s worth giving local WordPress development using Docker a shot. 🔫

Docker is an application that enables you to set up entire self-contained environments with a few simple commands. It is compatible with WordPress, and can be highly useful if you need to set up various local environments with different types of web servers or tools. 💻 Because each of your containers is essentially a virtual computer, you’re free to set up different technology stacks as needed.

Why you should consider using Docker to create a local WordPress environment

The Docker homepage.
Docker enables you to set up self-contained local development environments with ease.

In most cases, setting up a local WordPress development website requires that you install an entire environment in one fell swoop. Once you do that, you’re stuck with the environment you’ve chosen unless you want to uninstall the components and add new ones. For example, if you set up an Apache server on your computer, installing NGINX alongside it can be a real pain. However, swapping components may be necessary to recreate your production environments.

This brings us to Docker, a tool that enables you to set up isolated ‘containers’ that include entire development environments. Think of it as setting up a Virtual Machine (VM) without an operating system. These containers provide almost all the same benefits as VM, without weighing your system down. In practice, that means you can set up multiple environments on a normal computer.

As if that weren’t enough, you can also turn containers on or off at will. That way, the impact to your system will be minimal. Starting them back up when you need them just takes a single command.

⚙️ Key Features:

  • Create containers with isolated development environments.
  • Use fewer resources than with VMs.
  • Share your containers to make collaborations easier.

💵 Price:

Docker has a free personal plan. Premium-level plans start at $5 per month (billed annually at $60) and go up from there. Month-to-month billing is also available at a higher rate for all plans except for the highest level business plan, which requires an annual subscription.

How to get started with local WordPress development using Docker (in three simple steps)

To take advantage of local WordPress development using Docker, you’ll ideally want to be comfortable using the command line. However, don’t worry – even if you’ve hardly used it, all you need to do is follow our instructions. Without a working knowledge of the command line, you might not be able to improvise. But you’ll be able to get started just fine.

For this tutorial, we’ll be using the Windows version of Docker, but it’s also available for Linux and Mac. The commands themselves are interchangeable between platforms, so the process remains largely the same regardless of your operating system. Let’s get to work!

Step 1: Download and run Docker 🏃

First, visit the Docker desktop page and look for the Download for [OS] tab. Then, choose the version you want based on your operating system:

Download Docker for Mac, Windows, or Linux.

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 Compose V2, which is bundled in with Docker Desktop. It enables you to configure the services you want your container to have and set them up all at once. (Note that if you set up Docker before July 2023, you may need to migrate to Compose V2).

Start out by opening the command line again and entering this command:

mkdir wordpress-local && cd wordpress-local

This will create a directory called wordpress-local on your computer. Open that folder and create a new file called docker-compose.yml, using your favorite text editor.

Then, paste the following code snippet into the file:

version: '3'
    image: wordpress
      - ""
      WORDPRESS_DB_NAME: <your_database_name>
      WORDPRESS_DB_USER: <your_mysql_user>
      WORDPRESS_DB_PASSWORD: <your_mysql_user_password>
      - ./wp-content:/var/www/html/wp-content

    image: mysql:5.7
      MYSQL_ROOT_PASSWORD: <your_mysql_root_password>
      MYSQL_DATABASE: <your_database_name>
      MYSQL_USER: <your_mysql_user>
      MYSQL_PASSWORD: <your_mysql_user_password>
      - db-data:/var/lib/mysql


You’ll need to replace the placeholders with your own details. For example, you’ll need to assign specific ports and individual passwords by editing the values in the file.

When you’re ready, save your changes and close your editor. What you just did is instruct Docker to set up a new database for WordPress and install the software, along with all the other services it needs.

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, navigate to the directory you’ve just created, using the following command:

cd wordpress-local

Then, enter the following command:

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 our case, these were

Finishing up local WordPress development using Docker.

All that’s left to do now is follow the regular WordPress setup process in your browser.

The WordPress container you’ve just created will also appear in Docker Desktop:

WordPress container in Docker Desktop

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 stop
docker compose up -d

Now you’re ready to get rocking with your local WordPress development using Docker!

Conclusion 🧐

There are plenty of ways to set up local environments for WordPress development and create simple testing sites, but Docker stands out thanks to its compartmentalization features.

With it, you’ll be able to set up multiple environments side by side using different components and turn them on and off at will, which is a huge plus.

🧗🏼‍♀️ Here are the three steps to setting up local WordPress development using Docker:

  1. Download and run Docker 🏃
  2. Set up a container with a WordPress environment 🗄️
  3. Get your container up and running 🎯

Do you have any questions about how to get started with local WordPress development using Docker? Feel free to ask us in the comments section below!

Yay! 🎉 You made it to the end of the article!

Oldest Most Voted
Inline Feedbacks
View all comments
April 19, 2018 12:12 am

Update the bash command for making the directory and touching the file to the following:

mkdir wordpress-local && cd wordpress-local && touch docker-compose.yml

The second set of && are missing which could lead to some confusion for folks that are new to command line

April 15, 2018 6:57 pm

ERROR, You need to update the YML file, as it’s not workable with latest version of Docker.
docker-compose up -d
ERROR: In file ‘.docker-compose.yml’, service ‘image’ must be a mapping not a string.

April 23, 2018 10:21 pm
Reply to  Tapasfun

comment image
this indentation worked better, but still have errors.
Creating wordpresslocal_web_1 … error

ERROR: for wordpresslocal_web_1 Cannot start service web: b’driver failed programming external connectivity on endpoint wordpresslocal_web_1 (943b9b2c197b20b1e1df1e387bf649e885937e394fb523ad0c114bb5bb593627): Error starting userland proxy: listen tcp bind: cannot assign requested address’

ERROR: for web Cannot start service web: b’driver failed programming external connectivity on endpoint wordpresslocal_web_1 (943b9b2c197b20b1e1df1e387bf649e885937e394fb523ad0c114bb5bb593627): Error starting userland proxy: listen tcp bind: cannot assign requested address’
ERROR: Encountered errors while bringing up the project.

June 17, 2018 4:37 pm
Reply to  Craig

I ran into the same issue and was able to resolve it using the solution here: https://www.linode.com/docs/quick-answers/linux/wordpress-with-docker-compose/

Use this for your .yml file instead:

version: ‘3.3’

– db
image: wordpress:latest
– wordpress_files:/var/www/html
– “localhost”
restart: always
WORDPRESS_DB_PASSWORD: my_wordpress_db_password

image: mysql:5.7
– db_data:/var/lib/mysql
restart: always
MYSQL_ROOT_PASSWORD: my_db_root_password
MYSQL_USER: wordpress
MYSQL_PASSWORD: my_wordpress_db_password

March 21, 2018 3:30 pm

While this article does tell you how to get running WordPress locally, it does nothing to explain how to develop themes or plugins. After reading it, I still have no idea where to place my theme files, so that they can be reflected on the WordPress site running.

December 5, 2017 1:45 am

Any tips on

1. how to containerize the server so you can switch between nginx/apache?
2. switch out php versions
3. running multiple local wordpress sites
4. creating a local dns so that you can use domain names like xyz.dev for each site?

September 24, 2017 4:01 pm

The docker file throws an error because the indentation etc is not compliant with modern Docker Compose v3 syntax. The corrected content below will fix the issue:

version: “3.2”
image: wordpress
– mysql
– “”
# image: mysql:5.7
image: mysql:latest

August 8, 2017 9:04 pm

you mention in the beginning that windows users can use powershell if they want, but then you include all linux commands that don’t work in powershell (like && and touch)…

Cristian Uibar
February 28, 2018 1:48 pm
Reply to  DanielB

On windows you can use either the Ubuntu included in Windows 10 after the falls update or my preferred way is using the GIT SCM terminal which is bundled in the install. It acts like an emulator for bash and you can run almost all commands including ssh to servers and so on.

July 28, 2017 2:40 pm

Sadly i get this error: `ERROR: In file ‘./docker-compose.yml’, service ‘environment’ must be a mapping not an array.`

August 8, 2017 10:26 pm
Reply to  Moe

I am getting the same error as well

August 9, 2017 1:02 pm
Reply to  DanielB

Hey Daniel, i got this to work after i looked up another article (Dunno the link)

this is what my docker-compose.yml look like:

version: “2”
image: mariadb
– “8081:3306”
image: wordpress
– ./:/var/www/html
– “8080:80”
– my-wpdb:mysql

For me it was only for test-purpouse so i left the file unchanged, but keep in mind that you maybe need to alter the config for your needs 🙂 Did it work with your powershell?

July 22, 2017 10:23 pm


I am mac user and as per article, we follow all the steps. After successful setup, we faced below error:

“ERROR: for web Cannot start service web: driver failed programming external connectivity on endpoint wordpresslocal_web_1 (1ff06310645644c5868a17d9b5e634502b21348b24070fafea823008ccb23657): Error starting userland proxy: listen tcp bind: cannot assign requested address”

I really appreciated your help here. Well written, Nice Article !!

July 24, 2017 10:01 am
Reply to  CP

Resolved now.

April 23, 2018 11:06 pm
Reply to  CP

resolved how?

July 27, 2018 4:05 pm
Reply to  Craig


Abdul Qabiz
July 22, 2017 6:54 pm

Docker makes development, testing and development super fast and awesome.

Please add volume for wordpress files as well as mysql data in your docker-compose.yml.

I am sharing (below) what I use. This will mount local ‘src’ directory as volume in container, and all wordpress files will be copied (by container) in this. This allows quick development.

version: '3'
image: wordpress:latest
- 8080:80
- 8084:443
- ./data:/data
- ./src:/var/www/html
image: mysql:5.7
- data:/var/lib/mysql
image: phpmyadmin/phpmyadmin
- 8092:80

I must share some links here:

http://training.play-with-docker.com (best place to start learning Docker)
http://play-with-docker.com (create docker containers on the fly and quickly for temporary sessions)
– Launch WordPress on PWD: http://play-with-docker.com/?stack=https://raw.githubusercontent.com/docker-library/docs/0cb43ce8ad1da073bbc30c6245cdffb433ba51ba/wordpress/stack.yml


Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!