Hey guys , I have a half working solution - one service works on port 80 but my other service gets a '502 Bad Gateway' caused by: dial tcp 10.1.4.7:3000: connect: connection refused
This is the config:
traefik.toml
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.websecure]
address = ":443"
[entryPoints.staging]
address = ":3000"
[providers]
[providers.docker]
endpoint = "unix:///var/run/docker.sock"
network = "overlord_proxy"
swarmMode = true
watch = true
# Enable the file provider to define routers / middlewares / services in a file
[providers.file]
debugLogGeneratedTemplate = true
directory = "/etc/traefik/dynamic"
watch = true
[certificatesResolvers]
[certificatesResolvers.mytlschallenge]
[certificatesResolvers.mytlschallenge.acme]
email = "email"
storage = "/letsencrypt/acme.json"
tlschallenge = true
dyanmic config:
[http]
[http.routers]
[http.routers.whoami]
entryPoints = ["web"]
rule = "Host(`MYURL`)"
service = "whoami"
[http.routers.whoami-secure]
entryPoints = ["websecure"]
rule = "Host(`MYURL`)"
service = "whoami"
[http.routers.whoami.tls]
certResolver = "mytlschallenge"
[http.services]
[http.services.whoami]
enable = true
[http.services.whoami.loadBalancer]
[[http.services.whoami.loadBalancer.servers]]
port = "8000"
url = "http://whoami:8000"
[http.middlewares]
[http.middlewares.httpsredirect.redirectScheme]
scheme = "https"
and the docker-compose.yml:
version: "3.7"
services:
proxy:
image: traefik:v2.0.2
volumes:
# connect to docker socket for Traefik to listen to docker events
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "/etc/traefik/traefik.toml:/etc/traefik/traefik.toml"
- "/etc/traefik/dynamic/:/etc/traefik/dynamic/"
# Store certificates in ./letsencrypt/acme.json
- "./letsencrypt:/letsencrypt"
# command:
#- "--providers.file=true"
#- "--providers.file.filename=/traefik/traefik.toml"
networks:
- proxy
ports:
- "443:443"
- "80:80"
- "3000:3000"
deploy:
replicas: 1
placement:
constraints:
- node.role == manager
whoami:
image: jwilder/whoami
networks:
- proxy
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`URL`)"
- "traefik.http.routers.whoami.entrypoints=websecure"
- "traefik.http.routers.whoami.service=whoami@file"
networks:
proxy:
driver: overlay
And that works! I have another docker-compose which runs another whoami service but I get a 502 bad gateway error (connection refused) when I navigate to MYURL:3000
version: "3.7"
services:
staging:
image: jwilder/whoami
networks:
- overlord_proxy
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.staging.rule=Host(`MYURL`)"
- "traefik.http.routers.staging.entrypoints=staging"
- "traefik.http.services.staging.loadbalancer.server.port=3000"
- "traefik.http.routers.staging.service=staging@file"
networks:
overlord_proxy:
external: true
this is the dynamic config /etc/traefik/dynamic/staging.toml
:
[http]
[http.routers]
[http.routers.staging]
entryPoints = ["staging"]
rule = "Host(`MYURL`)"
service = "staging"
[http.routers.staging-secure]
entryPoints = ["staging"]
rule = "Host(`MYURL`)"
service = "staging"
[http.routers.staging-secure.tls]
certResolver = "mytlschallenge"
[http.services]
[http.services.staging]
enable = true
[http.services.staging.loadBalancer]
[[http.services.staging.loadBalancer.servers]]
port = "3000"
url = "http://staging:3000"
[http.middlewares]
[http.middlewares.httpsredirect.redirectScheme]
scheme = "https"