I set up a debian server where I installed docker and docker-compose.
I created in the home of my sudo user a folder with the following hierarchy:
~/docker-project
- docker-compose.yml
- /traefik/traefik.toml
I do a docker-compose up -d
everything is started I can reach traefik.mydomain.com that has working ssl certificate as does the other subdomains. But if I go to any of my subdomain to reach my dockerized web service, I get a bad gateway message in my browser. If I go to my server IP adress and put the right port, I see my webservice working perfectly.
So I think I've made a mistake configuring the docker / traefik relationship but I'm unable to find where.
Here is my traefik.toml
:
defaultEntryPoints = ["http", "https"]
################################################################
# Web configuration backend
################################################################
[web]
address = ":8080"
[web.auth.basic]
# User: user | Password: password
users = ["user:hashedpassword"]
################################################################
# Entry-points configuration
################################################################
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
################################################################
# Docker configuration backend
################################################################
[docker]
domain = "mydomain.com"
watch = true
exposedbydefault = false
################################################################
# Let's encrypt
################################################################
[acme]
email = "[email protected]"
storageFile = "/etc/traefik/acme.json"
onDemand = false
onHostRule = true
entryPoint = "https"
Here is my docker-compose.yml
:
version: '2'
services:
traefik:
restart: always
image: traefik
container_name: traefik
ports:
- '80:80'
- '443:443'
- '8080:8080'
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=dockerplatform_default'
- 'traefik.port=8080'
- 'traefik.frontend.rule=Host:traefik.mydomain.com'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik:/etc/traefik
plex:
image: linuxserver/plex
container_name: plex
environment:
- VERSION=latest
- PUID=1000
- PGID=1000
- TZ=TZ
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=dockerplatform_default'
- 'traefik.port=9001'
- 'traefik.frontend.rule=Host:plex.mydomain.com'
ports:
- '9001:32400'
volumes:
- 'plex:/config'
- 'plex_transcode:/transcode'
- '/home/downloader/Downloads:/data/'
plexpy:
image: linuxserver/plexpy
container_name: plexpy
environment:
- PUID=1000
- PGID=1000
- TZ=TZ
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=dockerplatform_default'
- 'traefik.port=9002'
- 'traefik.frontend.rule=Host:plexpy.mydomain.com'
ports:
- '9002:8181'
volumes:
- 'plexpy:/config'
transmission:
image: linuxserver/transmission
container_name: transmission
environment:
- PGID=1000
- PUID=1000
- TZ=TZ
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=dockerplatform_default'
- 'traefik.port=9003'
- 'traefik.frontend.rule=Host:bt.mydomain.com'
ports:
- '9003:9091'
- '51413:51413'
- '51413:51413/udp'
volumes:
- 'transmission:/config'
- '/home/downloader/Downloads:/downloads'
- '/home/downloader/Downloads:/watch'
volumes:
plex:
driver: local
plex_transcode:
driver: local
plexpy:
driver: local
transmission:
driver: local
Thank you for your help.
The "Bad Gateway" error is clearly related to networks. You can verify this by accessing to the docker engine of the swarm node where your Traefik container is loacted, and run a docker exec -ti <container id> sh to spawn an interactive commandline.
However, all the services just return "Bad Gateway" in the browser. This is a docker swarm network, and Traefik is running on the swarm manager. Traefik is launched through a stack with the following configuration:
In the traefik log I could see level=debug msg="'502 Bad Gateway' caused by: dial tcp 10.0.7.24.80: connect: no route to host" The network names are exactly the same and share the same id's on the swarm manager and worker node
So I managed to get an answer thanks to the terrific traefik slack channel!
So my containers are all in the same docker network including my traefik container.
The problem is that I mapped all my containers port to be accessible from the host machine.
Instead I should have only mapped traefik ports to the host machine and just exposed the ports of my web services containers so that traefik can listen to them inside the docker network where they are all in.
Change : - add expose - change traefik.port
I just had to do this changes in my docker-compose.yml:
version: '2'
services:
traefik:
restart: always
image: traefik
container_name: traefik
ports:
- '80:80'
- '443:443'
- '8080:8080'
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=dockerplatform_default'
- 'traefik.port=8080'
- 'traefik.frontend.rule=Host:traefik.mydomain.com'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik:/etc/traefik
plex:
image: linuxserver/plex
container_name: plex
environment:
- VERSION=latest
- PUID=1000
- PGID=1000
- TZ=TZ
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=dockerplatform_default'
- 'traefik.port=32400'
- 'traefik.frontend.rule=Host:plex.mydomain.com'
#ports:
# - '9001:32400'
expose:
- 32400
volumes:
- 'plex:/config'
- 'plex_transcode:/transcode'
- '/home/downloader/Downloads:/data/'
plexpy:
image: linuxserver/plexpy
container_name: plexpy
environment:
- PUID=1000
- PGID=1000
- TZ=TZ
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=dockerplatform_default'
- 'traefik.port=8181'
- 'traefik.frontend.rule=Host:plexpy.mydomain.com'
#ports:
# - '9002:8181'
expose:
- 8181
volumes:
- 'plexpy:/config'
transmission:
image: linuxserver/transmission
container_name: transmission
environment:
- PGID=1000
- PUID=1000
- TZ=TZ
labels:
- 'traefik.enable=true'
- 'traefik.docker.network=dockerplatform_default'
- 'traefik.port=9091'
- 'traefik.frontend.rule=Host:bt.mydomain.com'
#ports:
# - '9003:9091'
# - '51413:51413'
# - '51413:51413/udp'
expose:
- 9091
- 51413
volumes:
- 'transmission:/config'
- '/home/downloader/Downloads:/downloads'
- '/home/downloader/Downloads:/watch'
volumes:
plex:
driver: local
plex_transcode:
driver: local
plexpy:
driver: local
transmission:
driver: local
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With