for-win icon indicating copy to clipboard operation
for-win copied to clipboard

Docker swarm with windows 17.06-ce not working

Open johannesbrunner-wd opened this issue 9 years ago • 10 comments

Expected behavior

If I run a service in a swarm, then I can connect this service from outside the docker environment to use the service.

Actual behavior

It is not possible to connect to the service from outside a docker container.

Information

Used stack file

version: '3.3'

services: 
    database:
        image: microsoft/mssql-server-windows-express:latest
        environment: 
            - sa_password=Super@123
            - ACCEPT_EULA=Y
        ports: 
            - target: 1433
              published: 1433
              protocol: tcp
              mode: host
        networks:
            - internal-net
        volumes:
            - type: volume
              source: myswarm-data
              target: C:/data
        deploy:
            endpoint_mode: dnsrr
            mode: replicated
            replicas: 1
    databaseclient:
        image: microsoft/mssql-server-windows-express:latest
        environment: 
            - sa_password=Super@123
            - ACCEPT_EULA=Y
        networks:
            - internal-net        
        deploy:
            endpoint_mode: dnsrr
            mode: replicated
            replicas: 1
networks:
  internal-net:
    driver: overlay

volumes:
    myswarm-data:

#docker swarm init --advertise-addr=10.1.0.45 --listen-addr=10.1.0.45:2377
#docker stack deploy --compose-file docker-swarm.yml demo

Node Info

ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
u7rvhiolpaacbmk47gb9fgoi6 *   JBR                 Ready               Active              Leader

Stack Info

NAME                SERVICES
demo                2

Service Info

ID                  NAME                  MODE                REPLICAS            IMAGE                                           PORTS
58qdvbuhxd9j        demo_database         replicated          1/1                 microsoft/mssql-server-windows-express:latest
kuie6vw4b1xj        demo_databaseclient   replicated          1/1                 microsoft/mssql-server-windows-express:latest

Container Info

CONTAINER ID        IMAGE                                           COMMAND                  CREATED             STATUS              PORTS                    NAMES
c6e6da3fa3ea        microsoft/mssql-server-windows-express:latest   "cmd /S /C 'powers..."   13 minutes ago      Up 13 minutes                                demo_databaseclient.1.n11ew2y56ulvfphyjgqjkdrlr
42e96a64a4ba        microsoft/mssql-server-windows-express:latest   "cmd /S /C 'powers..."   20 minutes ago      Up 19 minutes       0.0.0.0:1433->1433/tcp   demo_database.1.pnxavbxm351dn6thkhv80l98h

Network Info

NETWORK ID          NAME                DRIVER              SCOPE
v3t2lx5spo32        demo_internal-net   overlay             swarm
u1b4pck3mn1n        ingress             overlay             swarm
7468ec10d76f        nat                 nat                 local
26aae22202cd        none                null                local

Inspect of Service database

[
    {
        "ID": "58qdvbuhxd9j2th7msxkxzdq7",
        "Version": {
            "Index": 20
        },
        "CreatedAt": "2017-07-20T06:18:20.3203009Z",
        "UpdatedAt": "2017-07-20T06:24:48.8717696Z",
        "Spec": {
            "Name": "demo_database",
            "Labels": {
                "com.docker.stack.image": "microsoft/mssql-server-windows-express:latest",
                "com.docker.stack.namespace": "demo"
            },
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "microsoft/mssql-server-windows-express:latest@sha256:07a9c84019b30a53c73febc1e33acf7887cf9919194681eb021f64e10806af22",
                    "Labels": {
                        "com.docker.stack.namespace": "demo"
                    },
                    "Env": [
                        "ACCEPT_EULA=Y",
                        "sa_password=Super@123"
                    ],
                    "Privileges": {
                        "CredentialSpec": null,
                        "SELinuxContext": null
                    },
                    "Mounts": [
                        {
                            "Type": "volume",
                            "Source": "demo_myswarm-data",
                            "Target": "C:/data",
                            "VolumeOptions": {
                                "Labels": {
                                    "com.docker.stack.namespace": "demo"
                                }
                            }
                        }
                    ],
                    "StopGracePeriod": 10000000000,
                    "DNSConfig": {}
                },
                "Resources": {},
                "RestartPolicy": {
                    "Condition": "any",
                    "Delay": 5000000000,
                    "MaxAttempts": 0
                },
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "windows"
                        }
                    ]
                },
                "Networks": [
                    {
                        "Target": "v3t2lx5spo321ti1xg58180pf",
                        "Aliases": [
                            "database"
                        ]
                    }
                ],
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "UpdateConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "RollbackConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "EndpointSpec": {
                "Mode": "dnsrr",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 1433,
                        "PublishedPort": 1433,
                        "PublishMode": "host"
                    }
                ]
            }
        },
        "PreviousSpec": {
            "Name": "demo_database",
            "Labels": {
                "com.docker.stack.image": "microsoft/mssql-server-windows-express:latest",
                "com.docker.stack.namespace": "demo"
            },
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "microsoft/mssql-server-windows-express:latest@sha256:07a9c84019b30a53c73febc1e33acf7887cf9919194681eb021f64e10806af22",
                    "Labels": {
                        "com.docker.stack.namespace": "demo"
                    },
                    "Env": [
                        "ACCEPT_EULA=Y",
                        "sa_password=Super@123"
                    ],
                    "Privileges": {
                        "CredentialSpec": null,
                        "SELinuxContext": null
                    },
                    "Mounts": [
                        {
                            "Type": "volume",
                            "Source": "demo_myswarm-data",
                            "Target": "C:/data",
                            "VolumeOptions": {
                                "Labels": {
                                    "com.docker.stack.namespace": "demo"
                                }
                            }
                        }
                    ]
                },
                "Resources": {},
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "windows"
                        }
                    ]
                },
                "Networks": [
                    {
                        "Target": "v3t2lx5spo321ti1xg58180pf",
                        "Aliases": [
                            "database"
                        ]
                    }
                ],
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "EndpointSpec": {
                "Mode": "dnsrr",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 1433,
                        "PublishedPort": 1433,
                        "PublishMode": "host"
                    }
                ]
            }
        },
        "Endpoint": {
            "Spec": {
                "Mode": "dnsrr",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 1433,
                        "PublishedPort": 1433,
                        "PublishMode": "host"
                    }
                ]
            },
            "Ports": [
                {
                    "Protocol": "tcp",
                    "TargetPort": 1433,
                    "PublishedPort": 1433,
                    "PublishMode": "host"
                }
            ]
        }
    }
]

Inspect of network internal-net

[
    {
        "Name": "demo_internal-net",
        "Id": "v3t2lx5spo321ti1xg58180pf",
        "Created": "2017-07-20T08:18:20.5073492+02:00",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "42e96a64a4babd0b0af87dc7a17a982a4fb5f1d4fa46281616078dfeb4425c5c": {
                "Name": "demo_database.1.pnxavbxm351dn6thkhv80l98h",
                "EndpointID": "2c9dfef73cfd42a7d229ea2efee08cc266f87c5f5eaec9cbccae321d3327d3d5",
                "MacAddress": "00:15:5d:67:ec:93",
                "IPv4Address": "10.0.0.2/24",
                "IPv6Address": ""
            },
            "c6e6da3fa3ea437b17f4da1853a49978445e9c8b4d615c27fd7c75cc71bd3066": {
                "Name": "demo_databaseclient.1.n11ew2y56ulvfphyjgqjkdrlr",
                "EndpointID": "d7132d23fd0d8f7aad6e153b4e7e88fab88b588b55d18551c3ec689ff89898ec",
                "MacAddress": "00:15:5d:67:eb:b8",
                "IPv4Address": "10.0.0.3/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097",
            "com.docker.network.windowsshim.hnsid": "202a0880-58cb-4ddd-aa31-aa68d5ad6c86"
        },
        "Labels": {
            "com.docker.stack.namespace": "demo"
        },
        "Peers": [
            {
                "Name": "JBR-92cdce637dec",
                "IP": "10.1.0.45"
            }
        ]
    }
]

Docker version

Client:
 Version:      17.06.0-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:30:30 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30 (minimum version 1.24)
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 22:19:00 2017
 OS/Arch:      windows/amd64
 Experimental: true

Steps to reproduce the behavior

On your windows 10 machine

  1. docker swarm init --advertise-addr=10.1.0.45 --listen-addr=10.1.0.45:2377
  2. docker stack deploy --compose-file docker-swarm.yml demo
  3. sqlcmd -S 10.1.0.45 -U sa --> ERROR
  4. sqlcmd -S JBR -U sa --> ERROR
  5. sqlcmd -S 127.0.0.1 -U sa --> ERROR
  6. sqlcmd -S JBR-92cdce637dec -U sa --> ERROR
  7. sqlcmd -S demo.database -U sa --> ERROR
  8. From external machine sqlcmd -S JBR -U sa --> ERROR
  9. From external machine sqlcmd -S 10.1.0.45 -U sa --> ERROR
  10. From inside docker env (I used databaseclient) sqlcmd -S demo.database -U sa -> OK

I am not able to connect to the published service from outside docker but this should work and I have no clue what the problem is. Please help.

johannesbrunner-wd avatar Jul 20 '17 06:07 johannesbrunner-wd

Does it work if you pass the port to sqlcmd? Eg. -S 10.1.0.45,1433. If you're trying to connect from the same host as where the containers are running, then note that you can't do loopback with Windows containers: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/

If that's the problem, you have to resolve the IP of the container currently hosting the sql server service (find it with docker ps):

docker inspect --format "{{.NetworkSettings.Networks.nat.IPAddress}}" <container-id>

friism avatar Jul 20 '17 15:07 friism

sqlcmd? Eg. -S 10.1.0.45,1433 --> ERROR

Yes I am on the same host but as I said on point 8. and 9. From external machine sqlcmd -S JBR -U sa --> ERROR From external machine sqlcmd -S 10.1.0.45 -U sa --> ERROR So even if I call from an external machine to my local machine the service is not reachable. And I do not know if the loopback problem exists also for the overlay network or is it just for nat network? But anyhow it does not solve my problem.

Regarding docker ps and docker inspect I think you are wrong, because I run in a docker swarm. You should not be able to reach your service directly from any host by its internal ip address. Instead you should reach it by the ip adress of the swarm node. Otherwise load balancing and all those swarm stuff will not work anyhow and then swarm mode does not make any sense.

So can anybody tell me a working setup for swarm mode on a single windows host? I am also aware of https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/swarm-mode but in their examples they do never use their started swarm so nobody knows if it is really working.

johannesbrunner-wd avatar Jul 21 '17 05:07 johannesbrunner-wd

@johannesbrunner-wd

I put together this youtube series showing the basics of running a Windows swarm cluster, and doing host mode service publishing with services running on the cluster: https://www.youtube.com/watch?v=ZfMV5JmkWCY

Does that help?

kallie-b avatar Jul 27 '17 09:07 kallie-b

@kallie-b thank you for your help. Nice youtube series. I did nearly the same setup on testing swarm on docker for windows server a couple of weeks ago, therefore I was already aware this. Unforutnatly it does not help.

johannesbrunner-wd avatar Aug 01 '17 06:08 johannesbrunner-wd

@johannesbrunner-wd

And I do not know if the loopback problem exists also for the overlay network or is it just for nat network

I believe it does. At least I cannot access services in swarm on the same machine, regardless if I use 127.0.0.1, localhost, or the private IP address. It works though if I access it from an external machine. It also works if I use the public IP address issued by AWS or Azure, in my case.

In your particular case, just thinking, probably you already did this. Have you tried running the database container without using swarm and reaching it from an external machine? It might be that you faced firewall restrictions.

alexander-frolov avatar Aug 10 '17 19:08 alexander-frolov

How resolve this problem ?

JaxLgj avatar Sep 29 '17 08:09 JaxLgj

I am also having the same problem. I am using Docker version 17.09.0-ce on Windows 10 withe version 17.03 (OS Build 15063.608). How do we resolve this issue?

santaji-cybage avatar Oct 06 '17 05:10 santaji-cybage

Hi all,

With our latest Windows Server release--Windows Server version 1709--we now support ingress routing mesh with Docker Swarm. For details, see this blog post.

Ingress routing mesh allows you to publish a service to a uniform port on all of the hosts in your cluster :)

This, however, won't resolve the localhost issue you're describing. Today, on Windows it isn't possible to access published ports for containers, from the same host where the container is published. We're working on a fix for this, but unfortunately it won't include published ports for swarm services (it will likely only cover containers attached to the default nat network).

One way to work around this, is to set up an external load balancer to balance traffic across the IP addresses and published ports for your services/containers. You can, for example, use an nginx load balancer to do this. In the YouTube series I linked to above, I show how this works using a setup with a containerized nginx server acting as a load balancer for my cluster. This way, you only need to keep track of one piece of info--the IP/port information for your load balancer, rather than for all of your containers/services.

kallie-b avatar Oct 10 '17 18:10 kallie-b

With Windows Server 2016 17.09 or Windows 10 17.09 and using Docker Version 17.10 everything works as expected.

johannesbrunner-wd avatar Dec 07 '17 15:12 johannesbrunner-wd

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle locked

docker-robott avatar Jun 23 '20 03:06 docker-robott