Docker IP and File provider

I currently have the following services in a dynamic file config

  services:
    web-service:
      loadBalancer:
        servers:
          - url: "http://172.23.0.3:80"

    api-service:
      loadBalancer:
        servers:
          - url: "http://172.23.0.2:8911"

I am using a static config of

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
  file:
    filename: "traefik_dynamic.yml"
    watch: true

These IPs are docker IPs to services running.

  web:
    build:
      context: .
      dockerfile: ./deploy/Dockerfile.nginx
    networks:
      - proxy

Everything works as expected. However, sometimes I find when I restart the docker services using compose, or down compose down and then up. Then the IPs change.

Is there a more reliable way to address these services?

Note: I am not keen on using labels. Some labels are OK, but I don't want to convert my whole setup to docker labels because IMO - it looks really messy.

Arguably the dynamic providers is one of the main points of running Traefik. The docker provider is what should be used for this, this is configured via labels.

You can configure containers to use static ip's if you really want to go the file provider route.

The only time I use a file provider for a router/service is when that service is not running in docker/swarm.

@cakiwi that's great, but these high-level abstractions and explanations to a new user like me are useless. Anways, I think you were trying to change how I configure it, even though I mentioned I don't want to use docker labels.

I have since had help from another traefik user who pointed out I can simply do the following:

Which is to use the names of the docker service.


  services:
    web-service:
      loadBalancer:
        servers:
          - url: "http://web:80"

    api-service:
      loadBalancer:
        servers:
          - url: "http://web:8080"

That's pretty much what I wanted to know and achieve exactly what I need.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.