Run WordPress and MySQL On Docker Linux Host

In this blog post, I will show you how to run WordPress inside Docker containers on a Linux container host.

Step by Step Guide

About the Deployment

This deployment will use Docker compose which will deploy the following:

  • a WordPress container running the latest WordPress build
  • a MySQL container running MySQL 5.7b server
  • All the data that the containers are using is stored on volumes.
  • After deployment WordPress will be available on port 80 however you can change it the file under ports.

YML File

Below, is the YML file that contains all the configuration.

You can change the values but make sure DB name-value matches in the DB and WordPress service.

version: '3.3'

     image: mysql:5.7
       - db_data:/var/lib/mysql
     restart: always
       MYSQL_ROOT_PASSWORD: enterpassword
       MYSQL_DATABASE: wp01
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

       - db
     image: wordpress:latest
       - wp_data:/var/www/html
       - "80:80"
     restart: always
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wp01
    db_data: {}
    wp_data: {}

I saved the file as docker-compose.yml inside a directory called wp01 but you can name the directory any name you like.


To deploy the solution, I will run the following command from the directory the file is located in.

docker-compose up -d

Configure WordPress

After I finished the deployment, I will access WordPress using my server IP address and the port I used.


Below you can see the configuration wizard.

After I finished with the configuration I logged in and updated the default post by adding a photo to it.


If you run the command below, you will see that Docker composes created two volumes.

The first volume (wp01_db_data) is for the MySQL server.

The second volume (wp01_wp_data) is for all WordPress images, etc.

docker volume ls

Check Status

To check the deployment status, I will use the command below.

docker-compose ps


To delete containers and leave the volumes attached I will run the command below.

If you keep the volumes and deploy again, the configuration will stay the same and nothing will be lost.

docker-compose down

To delete the containers and volumes I will run the command below.

Docker-compose down --volume

1 comment

  1. hi, i’m using fedora 32 with podman, i have this error:
    Traceback (most recent call last):
    File “/usr/local/bin/podman-compose”, line 8, in
    File “/usr/local/lib/python3.8/site-packages/”, line 1093, in main
    File “/usr/local/lib/python3.8/site-packages/”, line 611, in run
    File “/usr/local/lib/python3.8/site-packages/”, line 666, in _parse_compose_file
    TypeError: ‘str’ object does not support item assignment

    ¿can you help me? thanks a lot

Comments are closed.