2 minutes
How to: Use Docker to setup WordPress
This is my first attempt to use Docker to self host a Wordpress blog. I have used the following docker images:
- The official Wordpress image
- The official Nginx image
- The official Maria DB image
- jwilder’s docker-gen image. This is used to configure the nginx proxy
- jrcs’s letsencrypt-nginx-proxy-companion image. This is used to generete/renew my SSL certificated through Let’s Encrypt
I have chosen to store the persistent data into named volumes. The named volumes are:
certs
to store the SSL certificatesfigura.im-html
to store all the Wordpress html related contentfigura.im-db
to store the Maria DB data
Since I am using docker compose v2, I am required to use this Nginx template.
Any feedback on my approach si welcome. There is always space for improvement!
Below is my docker compose yml file.
version: "2"
services:
nginx:
image: nginx
container_name: nginx
ports:
- "80:80"
- "443:443"
volumes:
- "/etc/nginx/conf.d"
- "/etc/nginx/vhost.d"
- "/usr/share/nginx/html"
- certs:/etc/nginx/certs:ro
nginx-gen:
image: jwilder/docker-gen
container_name: nginx-gen
volumes:
- "/var/run/docker.sock:/tmp/docker.sock:ro"
- "/home/returntrip/wordpress/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro"
volumes_from:
- nginx
entrypoint: /usr/local/bin/docker-gen -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
letsencrypt-nginx-proxy-companion:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt-nginx-proxy-companion
volumes_from:
- nginx
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- certs:/etc/nginx/certs:rw
environment:
- NGINX_DOCKER_GEN_CONTAINER=nginx-gen
wordpress:
image: wordpress
container_name: wordpress-figura.im
volumes:
- figura.im-html:/var/www/html
environment:
- WORDPRESS_DB_PASSWORD=changeme_password
- VIRTUAL_HOST=figura.im
- LETSENCRYPT_HOST=figura.im
- LETSENCRYPT_EMAIL=[email protected]
mysql:
image: mariadb
container_name: mysql-figura.im
volumes:
- figura.im-db:/var/lib/mysql:rw
environment:
- MYSQL_ROOT_PASSWORD=changeme_password
volumes:
figura.im-html: {}
figura.im-db: {}
certs: {}