Skip to content

traefik docker compose network issue

For a while I have had an issue when I restart docker containers and some (intermittent) will have bad gateway when trying to reach trhough traefik. I suspected it is having a docker networking issue. Still testing but I believe I sorted it out. I thought it was the containers that belonged to my external and internal docker networks. Like wordpress needing both external for traefik and internal for database. I think that was wrong afterall and it was any container on the external network. Traefik may be binding to the wrong docker network.

example from docker compose file

  blog-1:
    image: "lscr.io/linuxserver/grav:latest"
    container_name: "blog-1"
    depends_on:
    - traefik
    restart: always
    labels:
      - "traefik.enable=true"
      - traefik.docker.network=external_network
      - "traefik.http.routers.blog-1.rule=Host(`blog.example.com`)"
      - "traefik.http.routers.blog-1.entrypoints=https"
      - "traefik.http.routers.blog-1.tls.certresolver=le-aws"
      - "traefik.http.routers.blog-1.tls=true"
      - "traefik.docker.network=traefik_external_network"
    volumes:
      - /stacks/html/blog.example.com/web:/config/
    networks:
      - external_network

networks:
  external_network:
     external: false
  internal_network:
     internal: false

WARNING: above label we needed the stack name traefik_ not just external_network

docker networks

ubuntu@server01:/stacks/stack01$ docker network ls
NETWORK ID     NAME                       DRIVER    SCOPE
3d7ad1df26f9   bridge                     bridge    local
bdb6efaa181b   host                       host      local
be6e03dc6ed5   none                       null      local
76207085707c   traefik_default            bridge    local
2a334976cbb7   traefik_external_network   bridge    local
f1abbe2c4374   traefik_internal_network   bridge    local

references

  • https://community.traefik.io/t/traefik-docker-network-doesnt-work-its-always-random/21015

-->