Wordpress with Traefik
In this guide we'll be creating a docker container for Wordpress with some added flags in our docker-compose.yml file for Traefik to automatically see, generate certs, and start routing to. If you have not configured Traefik yet, please use my Traefik Configs guide before proceeding.
We'll be using mysql and wordpress in our docker-compose.yml file. We'll also use the "proxy" network to communicate with our Traefik container as well as create the "wordpress" network that the wordpress container will use to communicate with its mysql instance so that mysql isn't exposed externally to anything.
Create the "wordpress" network
docker network create wordpress
Then create your docker-compose.yml with your favorite text editor
vim docker-compose.yml
Paste the below configs
version: '3.7'
services:
db:
image: "sql:8.0.22"
container_name: "db"
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=db
- MYSQL_ROOT_PASSWORD=changeme
- MYSQL_USER=db
- MYSQL_PASSWORD=changeme
volumes:
- "path/to/db/files":/var/lib/mysql
command: '--default-authentication-plugin=sql_native_password'
networks:
- wordpress
wordpress:
depends_on:
- db
image: "wordpress:latest"
container_name: "db"
restart: unless-stopped
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=db
- WORDPRESS_DB_PASSWORD=changeme
- WORDPRESS_DB_NAME=db
volumes:
- "path/to/html/files":/var/www/html
- "path-to-file"/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
networks:
- proxy
- wordpress
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.wordpress-secure.entrypoints=websecure"
- "traefik.http.routers.wordpress-secure.rule=Host(`yourdomain`)"
- "traefik.http.routers.wordpress-secure.tls.certresolver=letsencrypt"
networks:
proxy:
external: true
wordpress:
Now we just run
docker-compose up -d
And...That's it!
After some time, you should be able to navigate to https://yourdomain/wp-admin in your browser to finish your new Wordpress setup with a shiny new SSL certificate already in use.
Notes:
In this file we've added a volume for the "uploads.ini" file. The reason for this is so you don't have any issues with uploading images to your website that are over the (very small) default limit.
uploads.ini
file_uploads = On
memory_limit = 500M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 600
The configuration above will allow up to 500Mb files to be uploaded to your site. You probably don't need anything that large uploaded, so feel free to adjust to your needs.
You'll also want to ensure that you update the "yourdomain" and "path-to.." sections to match your installation.