Issue using external networks

I am using external network in docker-compose, but Traefik does not seem to understand it and throws the following error:

time="2019-10-30T19:24:25Z" level=warning msg="Could not find network named 'frontend' for container '/qatar_qatarwordpress_1'! Maybe you're missing the project's prefix in the label? Defaulting to first available network." providerName=docker container=qatarwordpress-qatar-d9266c3831f946e6bdfc5f8ee1a765beb6f369a68ab54dc1d312adede2289fa4 serviceName=qatarwordpress-qatar

and when I try to access the site I get a Gateway timeout error.
Traefik docker-compose:

version: '3.7'
services:
  traefik:
    image: traefik:latest
    volumes:
      # - ./traefik.toml:/etc/traefik/traefik.toml
      - /var/run/docker.sock:/var/run/docker.sock
      - "./letsencrypt/:/letsencrypt/"
      - "./logs/traefik.log:/traefik.log"
      - "./ssl/:/etc/traefik/ssl/"
      - "./dyn/:/dyn/"
      - "./traefik/:/opt/traefik/"
    restart: always
    networks:
      - frontend
    ports:
      - "80:80"
      - "443:443"
    command:
      - --api
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--metrics.prometheus=true"
      - "--global.sendAnonymousUsage=true"
      - "--entryPoints.web.address=:80"
      - "--entryPoints.websecure.address=:443"
      - "--log.level=DEBUG"
      - "--log.filepath=/opt/traefik/traefik.log"
      - "--accesslog=true"
      - "--accesslog.filepath=/opt/traefik/access.log"
      # Lets Encrypt settings:
      - "--certificatesresolvers.le.acme.dnschallenge=true"
      - "--certificatesresolvers.le.acme.dnschallenge.provider=route53"
      - "--certificatesresolvers.le.acme.email=webmaster@XXXXXXXXXX.com"
      - "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
    environment:
      # Lets Encrypt- Route53 DNS Challenge settings
      - "AWS_HOSTED_ZONE_ID=XXXXXXXXX"
      - "AWS_ACCESS_KEY_ID=XXXXXXXXXX"
      - "AWS_SECRET_ACCESS_KEY=XXXXXXXXXX"
    labels:
      # global redirect to https
      - "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.routers.redirs.entrypoints=web"
      - "traefik.http.routers.redirs.middlewares=redirect-to-https"
      # middleware redirect
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      # dashboard
      - "traefik.http.routers.traefik.rule=Host(`traefik.XXXXX.com`)"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.tls.certresolver=le"
      - "traefik.http.routers.traefik.entrypoints=websecure"
      - "traefik.http.routers.traefik.middlewares=admin"
      - "traefik.http.middlewares.admin.basicauth.users=admin:XXXXXXXXXX" 



  whoami:
    image: "containous/whoami"
    container_name: "simple-service"
    networks:
      - frontend
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`whoami.XXXXXXXXXX.com`)"
      - "traefik.http.routers.whoami.entrypoints=websecure"
      - "traefik.http.routers.whoami.tls.certresolver=le"
      - "traefik.http.routers.whoami.middlewares=auth"
      - "traefik.http.middlewares.auth.basicauth.users=myuser:XXXXXXXXXX"
networks:
  frontend:
    external:
      name: traefik-proxy

Wordpress docker-compose:

version: '3.7'
services:
  #Database
  db:
    image: mysql:latest
    volumes:
      - ./db_data:/var/lib/mysql
    restart: always
    networks:
      - backend
    command: mysqld --default_authentication_plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  #WordPress
  qatarwordpress:
    depends_on:
      - db
    image: wordpress:latest
    restart: always
    networks:
      - frontend
      - backend
    volumes:
      - ./html:/var/www/html
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=frontend"
      - "traefik.http.routers.wordpress.rule=Host(`qatar.XXXXXXXXXX.com`)"
      - "traefik.http.routers.wordpress.entrypoints=websecure"
      - "traefik.http.routers.wordpress.tls.certresolver=le"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress

networks:
  backend:
  frontend:
    external:
      name: traefik-proxy

What am I doing wrong?

The error message indicates that you don't have a network called frontend.

Run docker network ls to view the list of available networks. More information on Networking in Compose

I know I don't have a network called frontend... my network is call traefik-proxy and is listed as an external network at the bottom of both compose files:

frontend:
    external:
      name: traefik-proxy

So it should be looking for a network named traefik-proxy and not one named frontend

That's what threw you off the track... - it's wrong expectation.

Why is that the wrong expectation? It is an External Network and I explicitly listed that its external name is traefik-proxy.... This works for other docker'ed apps, what am I supposed to do to tell traefik that it needs to use the external networked named traefik-proxy?

Sorry, what "works for other docker'ed apps"? Can you give an example?

Because it does not align with reality of traefik implementation.

I hinted at that in my initial answer: run docker network ls and chose a network that is listed there, it cannot use a network that does not exist.

I have used a network that exists... I happens to be an External network... are you saying that Traefik does not support External networks in docker-compose?

Hello,

I used to call my network out in a similar way, but I believe that is an older way to name the network (I could be wrong). I'm now calling external: true - something like:

    networks:
      - traefik-proxy
      - backend

networks:
  backend:
  traefik-proxy:
    external: true

This identifies two networks for this compose file backend and traefik-proxy (which is external). You'll have to edit your Traefik compose file in a similar fashion. Could you give this a try?

@danielb change "traefik.docker.network=frontend" to "traefik.docker.network=traefik-proxy"

That was it... I was completely overlooking that line... I was focused on the standard docker-compose lines...

Thank you

1 Like