Docker Community Forums

Share and learn in the Docker community.

Work around 'network_mode' and 'networks' cannot be combined

Currently I have the docker-compose file:

version: '3.2'
services:
  traefik:
    image: "traefik:v2.2.0"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    networks:
      - traefik

networks:
  traefik:
    external: true

which allows me to use traefik to route requests to other docker containers sharing the traefik network.

I also want to be able to route requests to a route on the host machine (10.0.0.2) I can do this by changing the docker-compose.yml to:

version: '3.2'
services:
  traefik:
    image: "traefik:v2.2.0"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    network_mode: host

as it then uses the network of the host. The problem is that this then prevents traefik from being able to route to other containers! How can I have both?