Recipe: Run a local copy of a WordPress site with Docker

I recently decided to publish my articles in French and in English. First, I had to find and test plugins in order to choose one. So I spent some time, more than I expected, to make it work locally through Docker. Since I encountered some pitfalls, I decided to share the recipe.

1. Create the artefacts

We connect to the server with ssh, then we generate the “dump” file of the database. Here, under mysql:

mysqldump -u USER -p PASSWORD > /BLOG_BASE_DIR/blog.sql

Replace “USER”, “PASSWORD” and “BLOG_BASE_DIR” with proper values.

2. Download the artefacts

Locally, create a blog directory. This is where the following steps will be performed.


Then move blog.sql.

> mkdir db
> mv site/blog.sql db/.

3. Add directives to blog.sql

The blog.sql file contains the production values for WordPress. Two of them need to be modified to work in another environment.

Add this at the end of the blog.sql file.

UPDATE options SET option_value='' WHERE option_name IN ('siteurl', 'home');
UPDATE options SET option_value='LOCAL TRIAL' WHERE option_name='blogname';

⚠️ It is important NOT to add a slash at the end of the address, otherwise you will get endless redirects when you try to access your site.

4. Update wp-config.php

Ouvrez site/wp-config.php, et changez les valeurs DB_USER et DB_PASSWORD pour root.

define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', 'localhost');

5. Create file

docker exec blog_db_1 bash -c 'mysql -u root --password=root < /db/blog.sql'

docker exec blog_server_1 bash -c 'a2enmod rewrite'
docker exec blog_server_1 bash -c 'docker-php-ext-install pdo_mysql'
docker exec blog_server_1 bash -c 'docker-php-ext-install mysqli'
docker exec blog_server_1 bash -c 'service apache2 restart'

In detail: The first line loads the data into the database.

The following line installs modrewrite in apache, followed by two php modules: pdo_mysql and mysqli.

Finally, the apache2 service is restarted.

6. Create file docker-compose.yml

Here we use docker-compose to orchestrate two docker containers. It is simply installed with

pip install docker-compose

Here is the docker-compose.yml file

    image: mariadb:10.4.24
    hostname: blog-db
      - ""
      - ./db:/db:ro
    image: php:7.4-apache
    hostname: blog-server
      - ""
      - ./site:/var/www/html/
      - db

Obviously, use the database, php and apache versions that suit you. Of course, the present recipe may not be exact depending on those versions.

7. Start the containers

docker-compose up

8. Execute

In a new shell, run


9. Restart the apache container

In the shell where you ran docker-compose up, interrupt it (CTRL+C) and restart it (docker-compose up).

Explanation: The last command in has the effect of shutting down the apache container. (The cause being that containers shut down when the process running under PID 1 shuts down. Since apache is running under PID 1 and the service apache2 restart command shuts it down, the container shuts down).

10. Access your local copy

Start your browser and point it to



  1. Stop the containers CTRL+C in the shell where docker-compose up was run, and run docker-compose down.
  2. Delete the directory site

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: