Docker Community Forums

Share and learn in the Docker community.

Why "Connection refused" when I see docker daemon is listening on port?


#1

I’m working on the docker tutorial “Part 4: Swarm” which I can’t make it work. I’m on Windows 10 having set up two Docker Machines using Hyper-V. When I ssh onto the swarm manager which is a Docker-Machine I see following:

root@myvm1:~# docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                       PORTS
a4pkg0egf8x6        getstartedlab_web   replicated          3/3                 enceradeira/hellodocker:1   *:4000->80/tcp

Next I see that the docker daemon is listening as expected on port 4000:

root@myvm1:~# netstat -peanut
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2255/sshd
tcp        0      0 192.168.0.28:46672      192.168.0.27:7946       TIME_WAIT   -
tcp        0      0 192.168.0.28:46684      192.168.0.27:7946       TIME_WAIT   -
tcp        0      0 192.168.0.28:46678      192.168.0.27:7946       TIME_WAIT   -
tcp        0    340 192.168.0.28:22         192.168.0.11:57969      ESTABLISHED 3151/sshd: docker [
tcp        0      0 192.168.0.28:46682      192.168.0.27:7946       TIME_WAIT   -
tcp        0      0 192.168.0.28:46676      192.168.0.27:7946       TIME_WAIT   -
tcp        0      0 :::22                   :::*                    LISTEN      2255/sshd
tcp        0      0 :::4000                 :::*                    LISTEN      2287/dockerd
tcp        0      0 :::2376                 :::*                    LISTEN      2287/dockerd
tcp        0      0 :::2377                 :::*                    LISTEN      2287/dockerd
tcp        0      0 :::7946                 :::*                    LISTEN      2287/dockerd
tcp        0      0 ::ffff:192.168.0.28:7946 ::ffff:192.168.0.27:46070 TIME_WAIT   -
tcp        0      0 ::ffff:192.168.0.28:2377 ::ffff:192.168.0.27:55340 ESTABLISHED 2287/dockerd
tcp        0      0 ::ffff:192.168.0.28:7946 ::ffff:192.168.0.27:46064 TIME_WAIT   -
udp        0      0 0.0.0.0:4789            0.0.0.0:*                           -
udp        0      0 :::7946                 :::*                                2287/dockerd

But wenn I curl/telnet onto the port locally I get “Connection refused”:

root@myvm1:~# curl localhost:4000
curl: (7) Failed to connect to localhost port 4000: Connection refused

I know there is much more to it, there are docker networks, ingress, but I can’t get passed my assumption that I shouldn’t get an error on port 4000 given the daemon is listening on it.

Why do I get “Connection refused”?