I'm no specialist, but I followed this tutorial by Thibaut Devereaux (using Traefik:v2.2 as he does), and it works perfectly for the first wordpress instance. However, I can't get two wordpress sites to run on my Ubuntu server, even though Traefik should handle multiple services automatically. When I run docker-compose up -d on the second yaml, both sites are flat. When I shut down the second service, the first site works again.
I read everything available and followed the suggestion here, which led me to rename the db and many other things in the second wordpress yaml. But no joy. I assume there's something wrong in the second yaml, but it could also be the folder structure or an adjustment in Traefik itself.
My folder structure is like this:
home
-site1
-wordpress
-site2
-wordpress
The docker-compose.yml for site1 is this:
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: PWD
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.org`)"
- "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.org`)"
- "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: PWD2
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:
- "6378:6378"
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
The docker-compose.yml for site2 is this:
version: '3'
networks:
# enable connection with Traefik
traefik:
external: true
# network for the app
backend:
services:
wordpress2:
build:
# call the Dockerfile in ./wordpress
context: ./wordpress
restart: always
logging:
options:
max-size: "10m"
max-file: "3"
environment:
# Connect WordPress to the database
WORDPRESS_DB_HOST: db2:3306
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: PWB2
WORDPRESS_DB_NAME: wordpressdb2
volumes:
# save the content of WordPress an enable local modifications
- ./wordpress/data:/var/www/html
networks:
- traefik
- backend
depends_on:
- db2
- 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(`MYSITE2.org`)"
- "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(`MYSITE2.org`)"
- "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"
db2:
# 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: wordpressdb2
MYSQL_USER: USER
MYSQL_PASSWORD: PWD2
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
# Persist the database on disk
- ./db2:/var/lib/mysql
networks:
- backend
redis:
image: redis:6
restart: always
logging:
options:
max-size: "10m"
max-file: "3"
ports:
- "6378:6378"
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
Can anyone spot the mistake? Maybe there's something I need to change on the Traefik compose file? I am sure that a correct file based on the model by Devereaux would be useful to many people...
thanks, Brian Holmes
CodePudding user response:
The names of the Routers are conflicting. In the second website you should use different names.
For example:
traefik.http.routers.wordpresscp
should become traefik.http.routers.wordpresscp2
traefik.http.routers.wordpresscp-secured
should become traefik.http.routers.wordpresscp-secured2