Skip to content
Use WordPress with Docker using Docker Compose
PHP Shell Dockerfile
Branch: master
Clone or download
Latest commit 2189779 Feb 6, 2020

Docker Compose and WordPress

Build Status

Use WordPress locally with Docker using Docker compose

This setup comes shipped with:

  • A Dockerfile for extending a base image and using a custom Docker image with an automated build on Docker Hub
  • Custom domain for example myapp.local
  • Custom nginx config in ./nginx
  • Custom PHP php.ini config in ./config
  • Volumes for nginx, wordpress and mariadb
  • Bedrock - modern development tools, easier configuration, and an improved secured folder structure for WordPress
  • Composer
  • WP-CLI - WP-CLI is the command-line interface for WordPress.
  • PhpMyAdmin - free and open source administration tool for MySQL and MariaDB
  • CLI scripts
    • Create a self signed SSL certificate for using https
    • Trust certs in macOS System Keychain
    • Setup the local domain in your in /etc/hosts



  • Docker
  • Openssl for creatng the SSL cert. Install using Homebrew brew install openssl

Setup environment variables

Easily set your own local domain, db settings and more. Start by creating .env files, like the examples below.

For Docker and the cli scripts

Copy .env-example in the project root to .env and edit your preferences.



For WordPress

Copy .env-example in the src folder to .env and edit your preferences.

Use the following database settings:


Create SSL cert

cd cli

Note: OpenSSL needs to be installed.

Trust the cert in macOS Keychain

Chrome and Safari will trust the certs using this script.

In Firefox: Select Advanced, Select the Encryption tab, Click View Certificates. Navigate to where you stored the certificate and click Open, Click Import.

cd cli

Add the local domain in /etc/hosts

To be able to use for example https://myapp.local in our browser, we need to modify the /etc/hosts file on our local machine to point the custom domain name. The /etc/hosts file contains a mapping of IP addresses to URLs.

cd cli

The helper script can both add or remove a entry from /etc/hosts. First enter the domain name, then press "a" for add, or "r" to remove. Follow the instructions on the screen.

Install WordPress and Composer dependencies

cd src
docker-compose run composer install

If you have Composer installed on your computer you can also use cd src && composer install


docker-compose up -d

Docker Compose will start all the services for you:

Starting myapp-mysql    ... done
Starting myapp-composer ... done
Starting myapp-phpmyadmin ... done
Starting myapp-wordpress  ... done
Starting myapp-nginx      ... done

🚀 Open up https://myapp.local


PhpMyAdmin comes installed as a service in docker-compose.



When making changes to the Dockerfile, use:

docker-compose up -d --force-recreate --build



docker exec -it myapp-wordpress bash

Login to the container

wp search-replace --allow-root

Run a wp-cli command like this

You can use this command first after you've installed WordPress using Composer as the example above.



  • Readme improvements. Explain /etc/hosts better


  • Use Entrypoint command in Docker Compose to replace the domain name in the nginx config. Removing the need to manually edit the domain name in the nginx conf. Now using the .env value DOMAIN
  • Added APP_NAME in .env-example Thanks to @Dave3o3


  • Added .env support for specifying your own app name, domain etc in Docker and cli scripts.
  • Added phpMyAdmin. Visit


Useful Docker Commands

Login to the docker container

docker exec -it myapp-wordpress bash


docker-compose stop

Down (stop and remove)

docker-compose down


docker-compose rm -v


docker-compose up -d --force-recreate

Rebuild docker container when Dockerfile has changed

docker-compose up -d --force-recreate --build
You can’t perform that action at this time.