Because there are a number of files required to reproduce this issue, I put together a simple example that, on my Mac, reproduces the problem I will describe here. The repo is here:
As far as I am aware, I tagged the routes I was trying to make work, were created identically. The two routes in the Swarm stack that the Traefik container resides in work fine, the route in the adjacent portainer stack failed.
Configuration for traefik stack
version: "3.3"
services:
traefik:
image: traefik:2.0.1
command:
- --log.level=DEBUG
- --api.insecure=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --providers.file.directory=/traefik-config
- --providers.file.watch=true
- --api.debug=true
- --log.filepath=/traefik.log
- --accesslog.filepath=/traefik.access.log
- --log.format=json
ports:
- "80:80"
- "8199:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ${PWD}/volumes/traefik:/traefik
- ${PWD}/traefik.log:/traefik.log
- ${PWD}/traefik.access.log:/traefik.access.log
networks:
- skylab-overlay
influxdb:
image: influxdb:1.5.2
restart: always
volumes:
- ${PWD}/volumes/influxdb:/var/lib/influxdb
networks:
- skylab-overlay
labels:
- "traefik.enable=true"
- "traefik.http.routers.influxdb.rule=Host(`localhost`) && PathPrefix(`/influxdb`)"
- "traefik.http.routers.influxdb.entrypoints=web"
- "traefik.http.services.influxdb.loadbalancer.server.port=8086"
- "traefik.http.middlewares.influxdb-strip-prefix.stripPrefix.prefixes=/influxdb"
- "traefik.http.routers.influxdb.middlewares=influxdb-strip-prefix@docker"
grafana:
image: grafana/grafana:5.4.3
environment:
- GF_AUTH_ANONYMOUS_ENABLED
- GF_SERVER_ROOT_URL
# Grafana - overrides the grafana.ini file
# See http://docs.grafana.org/installation/configuration/#using-environment-variables
# See also http://docs.grafana.org/installation/docker/#configuration
- GF_AUTH_ANONYMOUS_ENABLED=${GF_AUTH_ANONYMOUS_ENABLED:-true}
- GF_SERVER_ROOT_URL=${GF_SERVER_ROOT_URL:-%(protocol)s://%(domain)s:%(http_port)s/grafana/}
restart: always
volumes:
- ${PWD}/volumes/grafana:/var/lib/grafana
networks:
- skylab-overlay
labels:
- "traefik.enable=true"
- "traefik.http.routers.grafana.rule=Host(`localhost`) && PathPrefix(`/grafana`)"
- "traefik.http.routers.grafana.entrypoints=web"
- "traefik.http.services.grafana.loadbalancer.server.port=3000"
- "traefik.http.middlewares.grafana-strip-prefix.stripPrefix.prefixes=/grafana"
- "traefik.http.routers.grafana.middlewares=grafana-strip-prefix@docker"
networks:
skylab-overlay:
# Note: external networks are expected to exist prior to bringing this configuration up.
# Use: docker network create -d overlay --attachable skylab-overlay
external: true
Configuration for portainer stack
version: '3.2'
services:
portainer:
image: portainer/portainer:1.22.0
command: -H tcp://tasks.agent:9001 --tlsskipverify
ports:
- "9000:9000"
- "8000:8000"
networks:
- agent_network
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
labels:
- "traefik.enable=true"
- "traefik.http.routers.portainer.rule=Host(`localhost`) && PathPrefix(`/portainer`)"
- "traefik.http.routers.portainer.entrypoints=web"
- "traefik.http.services.portainer.loadbalancer.server.port=9000"
- "traefik.http.middlewares.portainer-strip-prefix.stripPrefix.prefixes=/portainer"
- "traefik.http.routers.portainer.middlewares=portainer-strip-prefix@docker"
- "traefik.docker.network=agent_network"
agent:
image: portainer/agent:1.4.0
environment:
# REQUIRED: Should be equal to the service name prefixed by "tasks." when
# deployed inside an overlay network
AGENT_CLUSTER_ADDR: tasks.agent
# AGENT_PORT: 9001
# LOG_LEVEL: debug
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
networks:
- agent_network
deploy:
mode: global
placement:
constraints: [node.platform.os == linux]
networks:
agent_network:
driver: overlay
attachable: true
When attempting to connect to http://localhost/portainer the gateway times out. Connecting to http://localhost/influxdb or http://localhost/grafana work as expected (they are in the same swarm stack as the traefik container)
This is what it looks like from the web UI
Here are the service details.