Skip to content

Instantly share code, notes, and snippets.

@thibaut-d
Last active October 15, 2022 15:21
Show Gist options
  • Save thibaut-d/51cf5326e5017233ad4e6c3be77ae4b4 to your computer and use it in GitHub Desktop.
Save thibaut-d/51cf5326e5017233ad4e6c3be77ae4b4 to your computer and use it in GitHub Desktop.
wordpress docker-compose.yml with Redis and Traefik
version: '3'
networks:
# enable connection with Traefik
traefik:
external: true
# network for the app
backend:
services:
wordpress:
build:
# call the Dockerfile in ./wordpress
context: ./wordpress
restart: always
logging:
options:
max-size: "10m"
max-file: "3"
environment:
# Connect WordPrerss to the database
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpressuser
WORDPRESS_DB_PASSWORD: changeme
WORDPRESS_DB_NAME: wordpressdb
volumes:
# save the content of WordPress an enable local modifications
- ./wordpress/data:/var/www/html
networks:
- traefik
- backend
depends_on:
- db
- redis
labels:
# The labels are usefull for Traefik only
- "traefik.enable=true"
- "traefik.docker.network=traefik"
# Get the routes from http
- "traefik.http.routers.wordpresscp.rule=Host(`mysite.com`)"
- "traefik.http.routers.wordpresscp.entrypoints=web"
# Redirect these routes to https
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.routers.wordpresscp.middlewares=redirect-to-https@docker"
# Get the routes from https
- "traefik.http.routers.wordpresscp-secured.rule=Host(`mysite.com`)"
- "traefik.http.routers.wordpresscp-secured.entrypoints=web-secure"
# Apply autentificiation with http challenge
- "traefik.http.routers.wordpresscp-secured.tls=true"
- "traefik.http.routers.wordpresscp-secured.tls.certresolver=myhttpchallenge"
db:
# this is the database used by Wordpress
image: mysql:5.7
restart: always
logging:
options:
max-size: "10m"
max-file: "3"
environment:
# Connect WordPrerss to the database
MYSQL_DATABASE: wordpressdb
MYSQL_USER: wordpressuser
MYSQL_PASSWORD: changeme
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
# Persist the database on disk
- ./db:/var/lib/mysql
networks:
- backend
redis:
image: redis:6
restart: always
logging:
options:
max-size: "10m"
max-file: "3"
ports:
- "6379:6379"
networks:
- backend
# launch Redis in cache mode with :
# - max memory up to 50% of your RAM if needed (--maxmemory 512mb)
# - deleting oldest data when max memory is reached (--maxmemory-policy allkeys-lru)
entrypoint: redis-server --maxmemory 512mb -maxmemory-policy allkeys-lru
@jgontrum
Copy link

Thanks a lot for this file, it saved me literally hours of work! One correction: Line 76 should be:
entrypoint: redis-server --maxmemory 512mb --maxmemory-policy allkeys-lru - The double dash for the second argument is missing.

@baractald
Copy link

Yes, you are right.
afiter fix this, the redis can boot with warning like this,

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

follow the message to fix it and it's done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment