I'm using docker and have a few different services, each one is on a different subdomain.
When only one is running, Traefik will route and work normally.
When I run the second container, both of them get a gateway timeout.
The label in my docker-compose is as below:
- "traefik.http.routers.app1.rule=Host(`subdomain1.example.com`)"
and the other has
- "traefik.http.routers.app2.rule=Host(`subdomain2.example.com`)"
Is there a better way of handling multiple subdomains?
cakiwi
April 24, 2020, 12:42pm
2
That is how you do it. There must be something else in the config/labels messing you up.
Posting the full config will help.
Sure, this is practically identical in both containers, with the exception being the 'app1' and subdomains of course.
version: '3.3'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
volumes:
- ./db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL}
MYSQL_DATABASE: app1
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASS}
ports:
- "33067:3306"
networks:
- app1
app:
depends_on:
- db
build:
context: .
dockerfile: .docker/Dockerfile
restart: always
volumes:
- .:/var/www/html
labels:
- "traefik.enable=true"
- "traefik.http.routers.app1.rule=Host(`app1.example.com`)"
- "traefik.http.routers.app1.entrypoints=websecure"
- "traefik.http.routers.app1.tls.certresolver=myresolver"
- "traefik.http.routers.app1.middlewares=app1@docker"
- "traefik.http.middlewares.app1.headers.frameDeny=true"
- "traefik.http.middlewares.app1.headers.sslRedirect=true"
- "traefik.http.middlewares.app1.headers.contentTypeNosniff=true"
- "traefik.http.middlewares.app1.headers.browserXSSFilter=true"
- "traefik.http.middlewares.app1.headers.forceSTSHeader=true"
- "traefik.http.middlewares.app1.headers.STSSeconds=315360000"
- "traefik.http.middlewares.app1.headers.STSIncludeSubdomains=true"
- "traefik.http.middlewares.app1.headers.STSPreload=true"
environment:
MYSQL_DATABASE: app1
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASS}
networks:
- app1
- web
networks:
app1:
web:
external: true
volumes:
db_data:
cakiwi
April 26, 2020, 7:30pm
4
Yes looks okay to me.
One think I have experienced with Traefik and the containers being on multiple networks is that traefik will flip between the service having the two IPs.
Traefik only being on one of those networks will timeout. Use the traefik.docker.network=
to identify which network traefik should use to connect to the container(s).
I think that was the ticket!
Thanks for the help.