Launch WordPress in local with Docker Compose


If you are here you are bored of the classic WAMPP or XAMPP to launch your WordPress installation locally but you want to use the new technologies made available by Docker Compose and containers.

It may often be necessary to make changes or updates to the WordPress installation but it is not good practice to do so directly in a production environment. The solution is a local installation that allows you to modify the code as you wish, perhaps using the same data imported from the online DB.

To do this, the easiest choice is to use one of the complete packages with the software.

Run the following command to pull the images and launch the services locally. The first launch will be slower because Docker will have to download everything it needs to run its containers.

docker-compose up -d

You can also import manually your WordPress DB from the PhpMyAdmin installation that run with Docker:

Docker compose – the script

Here’s a docker-compose.yml file to launch an existing WordPress installation with Docker Compose, featuring automated import of the DB file:

version: "3.8"

  # Web server (modify based on your preference, e.g., nginx, apache).
      - db
      - wordpress_phpmyadmin
    image: wordpress:latest
      - ./wordpress:/var/www/html  # Replace "./wordpress" with your actual directory.
      - ./mysql/conf.d:/etc/mysql/conf.d  # Optional custom MySQL configuration.
      - "8383:80"  # Adjust port mapping if needed.
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: my_db_user # Replace with your database user.
      WORDPRESS_DB_PASSWORD: my_db_password # Replace with your database password.
      WORDPRESS_DB_NAME: my_wordpress_db # Replace with your database name.

  # MySQL database.
    image: mysql:5.7
      - ./wordpress.sql:/docker-entrypoint-initdb.d/wordpress.sql   # Mount existing database data.
      - ./mysql/conf.d:/etc/mysql/conf.d  # Optional custom MySQL configuration.
      MYSQL_ROOT_PASSWORD: my_db_password # Replace with your database password.

  # PhpMyAdmin installation to see your WordPress DB.
      - db
    image: phpmyadmin/phpmyadmin:latest
      - 8180:80
      PMA_HOST: db:3306
      MYSQL_ROOT_PASSWORD: my_db_password # Replace with your database password.
  # Mount your existing WordPress files
  # Mount your existing MySQL data and configuration (optional)

Important note: Before using this, replace the placeholders with your actual values. Additionally, ensure you have your existing WordPress files and database file ready.


  • The web service defines your container for the WordPress application.
  • The db service defines your container for the MySQL database.
  • We can use volumes to mount your local WordPress files and (optionally) existing MySQL data/configuration into the containers.
  • Environment variables provide credentials and connection details for WordPress to access the database.
  • The db_dump_path variable defines the location of your existing database dump file.
  • The import_data volume and command automatically import the database dump upon container creation.
  • You can optionally define external networks for further isolation.

Where to go

Once we have started the containers you can access the following URLs, one for the server, one for PhpMyAdmin.

WordPress installation: localhost:8383
DB installation: localhost:8180

Docker compose – how to finish

Once done with local testing and operations you can run the following simple command, to shut down your created Docker containers.

docker-compose down

Things to remember

  • Replace all placeholders with your actual values.
  • Ensure you have Docker and Docker Compose installed.
  • Adjust the configuration based on your specific needs, such as port mapping, custom MySQL configuration, etc.
  • Back up your existing WordPress files and database before proceeding.

References for docker-compose

That’s all for today.
Try it at home!

Be the first one to like this.
Please wait...

Leave a Reply

Thanks for choosing to leave a comment.
Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published.
Please do NOT use keywords in the name field. Let's have a personal and meaningful conversation.