Easy to use docker-compose managed multi-container setup for running wordpress
This repository contains files for running wordpress within a docker-compose managed multi-container setup, based on the official docker community image To enable non-tech savy people to use this repository, there are administration scripts for tasks like starting, stopping and backups included. Two docker-compose modes are available: production and develop. Check below for further information.
- Ubuntu > 18.04
- Docker Engine > 20.10
- docker-compose > 1.27.4
- Reverse proxy: caddy:2-alpine
- Application: wordpress:latest (apache2 + php)
- Database: mysql:5.7
- This mode is intended for running wordpress in a production environment with a standalone caddy reverse proxy.
- Beside listed requirements you need:
-
- Domain
-
- A/AAAA records pointing to your serverip
- TLS certificates will be provided from Lets Encrypt
- This mode runs a local wordpress instance to test this project or develop plugins.
- Beside listed requirements you need:
-
- Modified hostsfile with
wordpress.lan
pointing to127.0.0.1
- Modified hostsfile with
- TLS certificate will be a self-signed caddy-internal
- There are two docker-compose wrapper scripts included:
-
production.sh
is a wrapper fordocker-compose -f docker-compose-prod.yml --env=.env.prod
-
develop.sh
is a wrapper fordocker-compose -f docker-compose-dev.yml --env=.env.dev
- The wrapper scripts pass every argument to
docker-compose
, just with modifieddocker-compose
file location and.env
file location. Run the script without arguments to display help and available commands - Available commands
-
- backup: creates a backup of the mysql database and container volumes
-
- restore: restores mysql database and container volumes from a provided backup
-
- support-zip: creates a file containing application and service logs
-
- up -d: start docker containers
-
- stop: stop running docker containers
-
- down: stop and remove docker containers
-
- down -v: remove docker containers and volumes including application data. Use with care
-
- logs -f: display logs for running containers
-
- ps: display status of docker containers
-
- --help: display docker-compose help
- Planned functions are
-
- Viewing application/webserver logs from volumes instead of docker-compose logs -f
- Clone this repo and change directory
- Copy the example
.env.sample
file to.env.prod
- Copy the example
config/Caddyfile.sample
file toconfig/Caddyfile-prod
- Edit
.env.prod
andconfig/Caddyfile-prod
and check your config with./production.sh config
- If satisfied, start up your instance with
./production.sh up -d
- If youre getting the wordpress setup page with letsencrypt staging TLS-certificate , everything is working
- Stop the cluster with
./production.sh stop
and commentacme_ca
inconfig/Caddyfile-prod
to receive live letsencrypt TLS-certificate - Start cluster with
./production.sh up -d
- Clone this repo and change directory
- Copy the example
.env.sample
file to.env.dev
- Copy the example
config/Caddyfile.sample
file toconfig/Caddyfile-dev
- Edit
.env.dev
andconfig/Caddyfile-dev
and check your config with./develop.sh config
- Start your instance with
./develop.sh up -d
- Access your instance on
https://wordpress.lan
- Navigate to your wordpress page and follow instructions.
- To use an external docker managed reverse proxy and omit the default caddy webserver, docker-compose files with the
no-caddy
syntax are available. These files are identical to the default files beside missing the caddy configuration. -
- Adjust the COMPOSE_FILE variable in the
develop.sh
orproduction.sh
files and add-nocaddy
- Adjust the COMPOSE_FILE variable in the
-
- Rename or copy your
.env(.dev)
file to.env(.dev)-nocaddy
and adjust theENV_FILE
variable inside the file accordingly
- Rename or copy your
-
- Connect your external reverse proxy service to the
reverse-proxy-net
network and setexternal: true
within the network definition in the compose file. The hostname of your wordpress service is exposed toreverse-proxy-net
with the aliaswordpress_$(INSTANCE_NAME)
- Connect your external reverse proxy service to the
- Stick to the same configuration as above, but adjust the wordpress service to bind to a localhost:port combination
- Configure your external reverse proxy to proxy your domain to the localhost:port combination
- The official wordpress docker image is not able to send email (see this Github issue) , so best practice is to use a wordpress plugin with a free plan for SMTP providers like Sendgrid or Mailgun. Recommended plugin is https://wordpress.org/plugins/wp-mail-smtp/
- Use the webfrontend (auto)updater as the docker image files are only used on first start (see this Github issue)
- Use one of the popular wordpress plugins for backup/restore/migration
- Useful commands for migrating a wordpress instance with a change in baseurl
-
- Change baseurl
-
-
- Connect to mysqldb with
./develop.sh exec db sh -c 'exec mysql -uroot -p'
- Connect to mysqldb with
-
-
-
- Replace $OLD_BASE_URL and $NEW_BASE_URL accordingly
-
-
-
UPDATE wp_posts SET guid = replace(guid, '$OLD_BASE_URL','$NEW_BASE_URL'); UPDATE wp_posts SET post_content = replace(post_content, '$OLD_BASE_URL', '$NEW_BASE_URL');```
-
-
UPDATE wp_postmeta SET meta_value = replace(meta_value,'$OLD_BASE_URL','$NEW_BASE_URL');
-
-
- Change password of admin user
-
-
update wp_users SET user_pass = MD5('supersafepassword') where id=1;
-
Feel free to contribute, there are many improvements (check TODO strings in this repository) that still need to be made.