简体   繁体   中英

docker swarm - can't connect to service

I wanted to learn docker swarm but I can't get it working on a fresh azure instance with debian 10.1 (edit: I also tried debian 9.11)

I've isolated the problem only to the following commands, which should give me a simple nginx welcome page on port 9000:

docker swarm init
docker service create --name nginx -p 9000:80 nginx
curl -vvv localhost:9000

But actually curl hangs and the service does not respond:

* Expire in 1 ms for 1 (transfer 0x5574dbd88f50)
* Expire in 1 ms for 1 (transfer 0x5574dbd88f50)
* Expire in 1 ms for 1 (transfer 0x5574dbd88f50)
*   Trying ::1...
* TCP_NODELAY set
* Expire in 149998 ms for 3 (transfer 0x5574dbd88f50)
* Expire in 200 ms for 4 (transfer 0x5574dbd88f50)
* Connected to localhost (::1) port 9000 (#0)
> GET / HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.64.0
> Accept: */*
>

Running nginx with docker run on the machine works.

Running the above commands on my windows machine with docker also works.

But as soon as I'm using docker stack deploy or docker service create I can't connect to the exposed ports.

Has this something to do with debian? My setup? Did I missed some configuration? What can I do to investigate this problem?

Docker version is 19.03.4

It may be that curl is using IPv6 and Nginx isn't configured for it. Try:

curl -vvv 127.0.0.1:9000

Use the command docker service ls to list the services. There you will find a column with the state of your service. If it is listed, then proceed to know if there is any error. Use the command docker service ps nginx and check the column Current state . If everything is healthy then check nginx logs with the command docker service logs -f nginx . Show us that, and we can continue helping.

I ran into a similar problem with curl hanging for docker swarm. I initially thought it was an issue with traefik , however I could reproduce it with a simple httpd container also. So it is probably related to ipv6 being selected by curl. Here are some options that worked

  1. Adding -4 option to curl to force ipv4 . This helped, but was intermittent.
  2. Adding net.ipv6.conf.all.disable_ipv6 = 1 and net.ipv6.conf.default.disable_ipv6 = 1 to sudo vi /etc/sysctl.conf file and reloading it via sudo sysctl -p . Again intermittent.
  3. Creating an overlay network docker network create -d overlay dcm-net and in the docker-compose.yml file marking this network external as follows:
networks:
  dcm-net:
    external: true

Option 3 worked the best for now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM