StefanScherer / dockerfiles-windows

Various Dockerfiles for Windows Containers
MIT License
1.11k stars 396 forks source link

Traefik doesn't detect swarm services on overlay network windows #380

Closed bcowell closed 4 years ago

bcowell commented 5 years ago

Hi Stefan,

First of all thank you for all your work in the windows docker community.

Background: I've used your traefik-windows dockerfile successfully with docker compose on Windows Server 2016 and am able to view the dashboard of online services as well as use the whoami service. However I plan on creating many more swarm services in the future and would like to be able to spin up new swarm services via CLI (docker service create ...) instead of docker-compose.

Problem: I was able to edit your docker-compose file to work with an external overlay network and it works exactly the same. However when I attach new swarm services to the overlay network they aren't available through traefik, nor can I run a traefik service (the url of the dashboard just hangs indefinitely).

Working docker-compose.yaml with overlay network

NETWORK ID          NAME                DRIVER              SCOPE
743575wiqb4p        traefik_net         overlay             swarm

traefik.toml

################################################################
# api configuration backend
################################################################
[api]
entryPoint = "traefik"
dashboard = true
debug = true

################################################################
# Docker configuration backend
################################################################
[docker]
domain = "docker.localhost"
endpoint = "tcp://172.30.112.1:2375"
network = "net"
watch = true
# Use the IP address from the binded port instead of the inner network one
usebindportip = true
# increase docker api version to 1.24 with swarm-mode :-)
swarmmode = true

docker-compose.yaml

version: '3.0'

services:
  proxy:
    image: stefanscherer/traefik-windows
    command: --api --docker --logLevel=DEBUG --docker.endpoint=tcp://172.30.112.1:2375
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - E:/docker/traefik:C:/etc/traefik
    networks:
      - default
  whoami:
    image: stefanscherer/whoami
    labels:
      - "traefik.enable=true"
      - "traefik.backend=whoami"
      - "traefik.frontend.rule=PathStrip: /whoami/"
    networks:
      - default

networks:
  default:
    external:
      name: traefik_net

Traefik dashboard at :8080 image

CONTAINER ID        IMAGE                                  COMMAND                   CREATED             STATUS              PORTS                                        NAMES
5d4b91d91ce4        stefanscherer/whoami                   "\\http.exe"              2 minutes ago       Up 2 minutes        8080/tcp                                     traefik_whoami_2
fa28557874fc        stefanscherer/whoami                   "\\http.exe"              2 minutes ago       Up 2 minutes        8080/tcp                                     traefik_whoami_3
55504457491a        stefanscherer/traefik-windows          "/traefik --configfi…"    16 minutes ago      Up 16 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:8080->8080/tcp   traefik_proxy_1
23f3a8e41656        stefanscherer/whoami                   "\\http.exe"              4 hours ago         Up 16 minutes       8080/tcp                                     traefik_whoami_1

Trying to create another whoami service and attach to the overlay network:

docker service create `
  --name whoami2 `
  --network traefik_net `
  --label traefik.enable=true `
  --label traefik.backend=whoami `
  --label traefik.frontend.rule=PathPrefixStrip:/whoami2 `
  stefanscherer/whoami
CONTAINER ID        IMAGE                                  COMMAND                   CREATED             STATUS              PORTS                                        NAMES
c6a36172af80        stefanscherer/whoami:latest            "\\http.exe"              15 seconds ago      Up 9 seconds        8080/tcp                                     whoami2.1.r1fvcj9m51sxr9pshqh6weqca
5d4b91d91ce4        stefanscherer/whoami                   "\\http.exe"              21 minutes ago      Up 21 minutes       8080/tcp                                     traefik_whoami_2
fa28557874fc        stefanscherer/whoami                   "\\http.exe"              21 minutes ago      Up 21 minutes       8080/tcp                                     traefik_whoami_3
55504457491a        stefanscherer/traefik-windows          "/traefik --configfi…"    35 minutes ago      Up 35 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:8080->8080/tcp   traefik_proxy_1
23f3a8e41656        stefanscherer/whoami                   "\\http.exe"              5 hours ago         Up 35 minutes       8080/tcp                                     traefik_whoami_1

Log output of creating service

time="2019-01-18T16:23:02-05:00" level=info msg="Server configuration reloaded on :80"
time="2019-01-18T16:23:02-05:00" level=info msg="Server configuration reloaded on :8080"
time="2019-01-18T16:44:01-05:00" level=debug msg="Provider event received {Status:start ID:c6a36172af803c36e4b06b7af237a1c60b63677b928831efc7011259eb26993f From:stefanscherer/whoami:latest@sha256:5adf5f322fd412dcba5916cd06584ca4575c5fe8975adf8c5e892b904652792b Type:container Action:start Acto
r:{ID:c6a36172af803c36e4b06b7af237a1c60b63677b928831efc7011259eb26993f Attributes:map[name:whoami2.1.r1fvcj9m51sxr9pshqh6weqca com.docker.swarm.node.id:ya54gf7ggrwpxk7hb2apyt87u com.docker.swarm.service.id:xazrc721h9duforx87a538bbm com.docker.swarm.service.name:whoami2 com.docker.swarm.task:
com.docker.swarm.task.id:r1fvcj9m51sxr9pshqh6weqca com.docker.swarm.task.name:whoami2.1.r1fvcj9m51sxr9pshqh6weqca image:stefanscherer/whoami:latest@sha256:5adf5f322fd412dcba5916cd06584ca4575c5fe8975adf8c5e892b904652792b]} Scope:local Time:1547847841 TimeNano:1547847841422023100}"
time="2019-01-18T16:44:01-05:00" level=debug msg="originLabelsmap[com.docker.swarm.node.id:ya54gf7ggrwpxk7hb2apyt87u com.docker.swarm.service.id:xazrc721h9duforx87a538bbm com.docker.swarm.service.name:whoami2 com.docker.swarm.task: com.docker.swarm.task.id:r1fvcj9m51sxr9pshqh6weqca com.docker
.swarm.task.name:whoami2.1.r1fvcj9m51sxr9pshqh6weqca]"
time="2019-01-18T16:44:01-05:00" level=debug msg="allLabelsmap[:map[]]"
time="2019-01-18T16:44:01-05:00" level=debug msg="Filtering container with empty frontend rule /whoami2.1.r1fvcj9m51sxr9pshqh6weqca "
time="2019-01-18T16:44:01-05:00" level=debug msg="originLabelsmap[traefik.enable:true com.docker.compose.container-number:2 com.docker.compose.oneoff:False com.docker.compose.project:traefik com.docker.compose.service:whoami com.docker.compose.version:1.11.2 traefik.backend:whoami traefik.fro
ntend.rule:PathStrip: /whoami/ com.docker.compose.config-hash:3eee9ccd594b8a7318a7cabe1aa9b6b954572107e3af7eacbc12b4f18ce5f010]"
time="2019-01-18T16:44:01-05:00" level=debug msg="allLabelsmap[:map[traefik.backend:whoami traefik.frontend.rule:PathStrip: /whoami/ traefik.enable:true]]"
time="2019-01-18T16:44:01-05:00" level=debug msg="originLabelsmap[com.docker.compose.config-hash:3eee9ccd594b8a7318a7cabe1aa9b6b954572107e3af7eacbc12b4f18ce5f010 com.docker.compose.project:traefik com.docker.compose.service:whoami com.docker.compose.version:1.11.2 traefik.backend:whoami traef
ik.frontend.rule:PathStrip: /whoami/ com.docker.compose.container-number:3 com.docker.compose.oneoff:False traefik.enable:true]"
time="2019-01-18T16:44:01-05:00" level=debug msg="allLabelsmap[:map[traefik.enable:true traefik.frontend.rule:PathStrip: /whoami/ traefik.backend:whoami]]"
time="2019-01-18T16:44:01-05:00" level=debug msg="originLabelsmap[com.docker.compose.container-number:1 com.docker.compose.oneoff:False com.docker.compose.project:traefik com.docker.compose.service:proxy com.docker.compose.version:1.11.2 org.label-schema.version:v1.7.4 com.docker.compose.conf
ig-hash:f1916e745b074b90457c2ea861f51f403de00efbc4a73f4fca3cfec76ab9d071 org.label-schema.description:A modern reverse-proxy org.label-schema.docker.schema-version:1.0 org.label-schema.name:Traefik org.label-schema.url:https://traefik.io org.label-schema.vendor:Containous]"
time="2019-01-18T16:44:01-05:00" level=debug msg="allLabelsmap[:map[]]"
time="2019-01-18T16:44:01-05:00" level=debug msg="originLabelsmap[com.docker.compose.config-hash:3eee9ccd594b8a7318a7cabe1aa9b6b954572107e3af7eacbc12b4f18ce5f010 com.docker.compose.container-number:1 com.docker.compose.oneoff:False com.docker.compose.project:traefik com.docker.compose.version
:1.11.2 traefik.enable:true traefik.frontend.rule:PathStrip: /whoami/ com.docker.compose.service:whoami traefik.backend:whoami]"
time="2019-01-18T16:44:01-05:00" level=debug msg="allLabelsmap[:map[traefik.enable:true traefik.frontend.rule:PathStrip: /whoami/ traefik.backend:whoami]]"

I've also tried many variations of options for the service like: --publish mode=host,target=8080 --label traefik.docker.network=traefik --label traefik.port=80 (and 8080) --endpoint-mode=dnsrr with no luck.

Expected result: The whoami2 service should show up on the traefik dashboard and I should be able to access it from /whoami2

Actual result:

image

image

Any help would be appreciated.

Thanks, Brayden

StefanScherer commented 5 years ago

Hi @bcowell Thanks for trying Traefik on Windows. Currently I'm trying Traefik on Windows Server 2019 / Windows 10 1809, but I had not yet time to run it in swarm mode. I first updated the docker-compose example in this repo to get rid of the TLS certs by using the named pipe. My next steps are to try swarm mode as described in https://dockerswarm.rocks, but on a Windows Server 2019.

bcowell commented 5 years ago

Hey @StefanScherer ,

No worries. Thanks for the link it looks promising!

mgiangrandi commented 5 years ago

Hi @StefanScherer , thank you very much for the project, it's helping us a lot!

Unfortunately, right now, I've got the same issue as @bcowell because, in Swarm Mode, Traefik does not detect services created on overlay networks.

I'm using this docker-compose inside Windows Server 2019 (docker version 18.09.1):

version: '3.4'
services:
  traefik:
    image: stefanscherer/traefik-windows
    command: --docker --docker.watch --web --docker.endpoint=npipe:////./pipe/docker_engine --logLevel=DEBUG
    ports:
      - "8080:8080"
      - "85:80"
    isolation: process # workaround for https://github.com/containous/traefik/issues/4409
    volumes:
      - .:C:/etc/traefik
      - type: npipe
        source: \\.\pipe\docker_engine
        target: \\.\pipe\docker_engine

networks:
  default:
    external:
      name: nat

Then, I try to create a service:

docker service create --name=tbbackend --replicas 5 --endpoint-mode dnsrr 
--label "traefik.enable=true" --label "traefik.port=10000" --label "traefik.backend=tbbackend" 
--label "traefik.frontend.rule=PathPrefix:/" --label "traefik.backend.loadbalancer.sticky=true"
--label "traefik.docker.network=nat" myrepo/tbbackend:v1

Traefik can't redirect the calls on the various service endpoints and, also, entering the dashboard (:8080), all I can see is a blank page...

Hope you can help me in some way :)

Thanks again!

Cheers, Mattia

mmgil commented 5 years ago

This dont working in Stack file

type: npipe
        source: \\.\pipe\docker_engine
        target: \\.\pipe\docker_engine
StefanScherer commented 5 years ago

@mmgil This will work in the next release of Docker EE as the PR for it got merged. I used the nightly builds to demo it in February at a conference.

jbella commented 5 years ago

@StefanScherer What version of Docker EE supports this?

StefanScherer commented 5 years ago

@jbella it‘s the 19.03 release, there are release candidates available and the final release will be in the near future.

jbella commented 5 years ago

Thanks for the info @StefanScherer

Is running the 19.03-ee the only way to get Traefik to run on a Windows Swarm cluster? (I am currently running 18.09.7 on Windows Server 2019)

I have software that is currently working using linux containers using Traefik as the loadbalancer. I am trying to figure out the best way (most production ready) to get this working on a windows based swarm cluster. It looks like the LCOW stuff is still pretty experimental so I thought I would try the route of building windows containers for my software.

simmohall commented 5 years ago

Hi folks, Again awesome with with the docker on windows. I still can't get the traefik service to run in a docker swarm. I'm running the EE 19.03.1 version and using the below i still get 'services.traefik.volumes.0 must be a string'

StefanScherer commented 4 years ago

Closing this, nothing I can do in this repo.