/wordpress-nginx-docker-compose

Use WordPress with Docker using Docker Compose

Primary LanguagePHP

Docker Compose and WordPress

Build Status

Use WordPress with Docker using Docker compose

  • Dockerfile for extending a base image and install wp-cli
  • Local domain ex myapp.local
  • Custom nginx config in ./nginx
  • Custom php.ini config in ./config
  • Volumes for nginx, wordpress and mariadb
  • WordPress using Bedrock - modern development tools, easier configuration, and an improved folder structure
  • CLI scripts for creating a self signed SSL certificate for using https
  • CLI script for trusting certs in macOS System Keychain
  • CLI script for setting up an entry in your host file

Setup

Requirements

Install Docker

Create SSL cert

cd cli && ./create-cert.sh

Edit the script to your your custom domain, this example uses myapp.local

Trust cert in macOS Keychain. (Chrome and Safari will trust the certs, for Firefox: add them in preferences)

cd cli && ./trust-cert.sh

Edit the script to your your custom domain, this example uses myapp.local

Setup vhost in /etc/hosts

cd cli && ./setup-hosts-file.sh

Follow the instructions. For example use myapp.local

Setup ENV

cd src
cp .env.example .env

Use the following database settings:

DB_HOST=mysql:3306
DB_NAME=myapp
DB_USER=root
DB_PASSWORD=password

Install WordPress and Composer dependencies

cd src
composer install

You can also use composer like this: docker-compose run composer update

Run

docker-compose up -d

🚀 Open up https://myapp.local

Notes:

When making changes to the Dockerfile : Use docker-compose up -d --force-recreate --build.

Tools

wp-cli

docker exec -it myapp-wordpress bash
wp search-replace https://olddomain.com https://newdomain.com --allow-root

Useful Docker Commands

Login to the docker container

docker exec -it myapp-wordpress bash

Stop

docker-compose stop

Down (stop and remove)

docker-compose down

Cleanup

docker-compose rm -v

Recreate

docker-compose up -d --force-recreate

Rebuild docker container when Dockerfile has changed

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