WordPress on Docker
In this article, we will see how to install WordPress in docker and use it for local development purposes.
To run WordPress you need
- PHP
- MySQL
- nginix
If you are a WordPress developer it is very useful to run the WordPress on a Docker container so that you can set up the local WordPress development environment.
Step 1 – Install and run the Docker desktop
Step 2 – Create docker-compose.yaml
and add the following configuration
Using official WordPredd Docker Image with environmental variables.
MySQL official Docker Image with environmental variables.
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=wordpress
- MYSQL_USER=ordpress
- MYSQL_PASSWORD=wordpress
networks:
- wpsite
# WordPress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8080:80"
volumes: ["./:/var/www/html"]
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
networks:
- wpsite
volumes:
db_data:
networks:
wpsite:
Step 3: Create Docker images
Run the following command in the terminal. Your working directory should be where you have the docker-compose.yaml
file
docker-compose up
You can see the following docker images on your Docker Desktop

You can open the WordPress site with http://localhost:8080/ URL and setup the site by giving the admin user name and password.
How do you edit the files of WordPress?
WordPress files can be seen in your working directory as shown in the below image

> docker ps