DevOp, Technical

Host your WordPress with docker container

Develop and running your WordPress site with Docker container given us a large opportunity for developing and delivery our change to WordPress site quick and efficiently. This article will guide you through simple process to easily run your WordPress within Docker container.


  • Installed Docker container.
  • Installed Docker Composer.
  • Linux base operation system.
  • Basic understand of WordPress system and Docker.

Let’s get started!

Project structure

First open your developing directory on your WordPress project. This could be your wp-content folder. Your directory structure will some thing look like this:

Next, create a docker-compose.yml file on your project folder with the following content:

version: '3'

    image: mysql:8
      - db_data:/var/lib/mysql
    restart: always
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

      - db
    image: wordpress:php8.0-apache
      - "8000:80"
    restart: always
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    working_dir: /var/www/html
      - ./themes:/var/www/html/wp-content/themes
      - uploads:/var/www/html/wp-content/uploads
  db_data: {}
  uploads: {}

The above file content will create 2 containers within docker composer. One is the SQL database for your WordPress container and one is your WordPress container. We will run the WordPress with port 8000 and mount 2 volumes: one for our database and one for our uploads folder so that the data persistence even when we restart or delete our container.

One note here is that ./themes:/var/www/html/wp-content/themes row tell that we will copy all of our developing themes to our WordPress container so that every change to the theme we work will be delivered to the container.

Build and run your project

After setting up all thing, run sudo docker-compose up -d on your project folder. This command will execute your docker-compose.yml file in detached mode, pulling all needed images and run it. Continue to run command sudo docker ps to check if your database and wordpress images are up and running, the result will something like this:

CONTAINER ID   IMAGE                     COMMAND                  CREATED        STATUS        PORTS                                   NAMES
10ace87d1ccd   wordpress:php8.0-apache   "docker-entrypoint.s…"   22 hours ago   Up 22 hours>80/tcp, :::8000->80/tcp   june_dang_blog-wordpress-1
45dcbc0d302d   mysql:8                   "docker-entrypoint.s…"   22 hours ago   Up 22 hours   3306/tcp, 33060/tcp                     june_dang_blog-db-1

Finished WordPress set up

Open your browser with ip address http://localhost:8000 and you can see welcome page of WordPress. If you first start the WordPress app, it will prompt you to select language and create an admin account.

Following WordPress started page and you all have done. Now you can develop and delivery your WordPress application with Docker container.