Search code examples
amazon-web-servicesdockerdocker-composedocker-swarmtraefik

Setting up traefik with docker services on aws


I'm trying to use traefik in fron't of my docker services (although only 1 docker service to start with) I've been able to set-up traefik however it is ignoring the labels that I include in my docker compose file. I'm using a docker swarm on AWS.

The log indicates "Filtering container without port and no traefik.port label service_myapp.3"

I've inspected both the service, and a the containers, using docker service inspect and docker container inspect and the labels are present.

The traefik web console shows a docker tab, but with nothing under it.

Here is my traefik.toml

logLevel = "DEBUG"
traefikLogsFile = "/var/logs/traefik.log"

[entryPoints]
    [entryPoints.http]
    address = ":80"
[web]
address = ":8080"

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "docker.localhost"
watch = true
swarmmode = true
exposedbydefault = false

and here is my docker compose yml

version: "3.4"
configs:
  traefik:
    external:
      name: traefik
services:
  traefik:
    image: traefik:1.3.5
    configs:
      - source: traefik
        target: /etc/traefik/traefik.toml
        mode: 0400
    depends_on:
      - myapp
    volumes:
      - traefiklogs:/var/logs
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    networks:
      - public
      - private
    tty: true
    deploy:
      mode: global
      placement:
        constraints:
          - node.role == manager
  myapp:
    image: myapp
    deploy:
      endpoint_mode: vip
      replicas: 3
      restart_policy:
        condition: on-failure
    ports:
      - "4000:8080"
    networks:
      - public
      - private
    labels:
      traefik.frontend.rule: "Host:myapp.myapp.com"
      traefik.backend: "myapp"
      traefik.docker.network=: "public"
      traefik.enable: "true"
      traefik.port: "4000"
networks:
  public:
    driver_opts:
      encrypted: 1
  private:
    driver_opts:
      encrypted: 1
volumes:
  sqldata:
  traefiklogs:

Solution

  • With swarmmode = true, you need to set the labels on the service instead of the containers. That's done by defining the labels within the deploy section:

    version: "3.4"
    configs:
      traefik:
        external:
          name: traefik
    services:
      traefik:
        image: traefik:1.3.5
        configs:
          - source: traefik
            target: /etc/traefik/traefik.toml
            mode: 0400
        depends_on:
          - myapp
        volumes:
          - traefiklogs:/var/logs
          - /var/run/docker.sock:/var/run/docker.sock
        ports:
          - 80:80
          - 443:443
          - 8080:8080
        networks:
          - public
          - private
        tty: true
        deploy:
          mode: global
          placement:
            constraints:
              - node.role == manager
      myapp:
        image: myapp
        deploy:
          endpoint_mode: vip
          replicas: 3
          restart_policy:
            condition: on-failure
          labels:
            traefik.frontend.rule: "Host:myapp.myapp.com"
            traefik.backend: "myapp"
            traefik.docker.network=: "public"
            traefik.enable: "true"
            traefik.port: "4000"
        ports:
          - "4000:8080"
        networks:
          - public
          - private
    networks:
      public:
        driver_opts:
          encrypted: 1
      private:
        driver_opts:
          encrypted: 1
    volumes:
      sqldata:
      traefiklogs: