Docker Community Forums

Share and learn in the Docker community.

Connection refused: from one Container to another

docker

(Vramana) #1

I am unable to make one container talk to another, even though both are on same network (bridge type, created by using - docker network create --driver bridge isolated_nw).
The containers are able to ping each other, but not able to connect to a port on the other, throws up error connection refused with respective port number.
The concerned ports have been exposed/published.
I can see on doing docker network inspect isolated_nw that the 2 containers are indeed connected to this network.
Did try to go thru the Docker docs / examples - but not sure what need to be done to make this work.


(Sreenivas Makam) #2

Need more details(swarm/non-swarm, what ports being exposed, linux/windows, same host/across hosts, docker inspect command outputs) to suggest possible problems.


(Vramana) #3

Thanks.
To summarize - the container running the nginx image is not able to connect/communicate with the container running ethereum image .

Details are ->

  1. About the way images are built =>
    1.for Image1, which is the Ethereum one - Dockerfile is as follows ->

    FROM ubuntu:xenial
    ENV DEBIAN_FRONTEND noninteractive

    RUN apt-get update &&
    apt-get -y -qq upgrade &&
    apt-get -y -qq install software-properties-common &&
    add-apt-repository ppa:ethereum/ethereum &&
    apt-get update &&
    apt-get -y -qq install geth solc &&
    apt-get clean &&
    rm -rf /var/lib/apt/lists/*

    EXPOSE 8545
    EXPOSE 30303

    1. The second image used is the nginx one - to be the webServer - from dockerhub, hence no dockerfile.
  2. Regarding the corresponding containers -

    1. I had tried to run these images in the following 2 ways
    • a.) one creating a container with bridge network (isolated_nw) explicitly set as mentioned earlier.
    • b.) the other by create a container with bridge network =‘host’ (that expereince will articulated SEPARATELY)
    1. Outcomes using isolated_nw

    2. Containers created with following commands -

    3. The ethereum one => docker container run -it --cap-add=NET_ADMIN --network=isolated_nw --name=eth_poc_isolatednw -p 8545:8545 -p 30303:30303 --entrypoint bash eth_setup_image

    4. The nginx one => docker run -d --cap-add=NET_ADMIN --name=nginx-webserver_isolated --network=isolated_nw -p 9015:80 nginx_plus_changes

    5. ifconfig outpt ->

      1. On ethereum container, ifconfig reveals the following -
        eth0 Link encap:Ethernet HWaddr 02:42:ac:12:00:02
        inet addr:172.18.0.2 Bcast:0.0.0.0 Mask:255.255.0.0
        UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
        RX packets:788 errors:0 dropped:0 overruns:0 frame:0
        TX packets:749 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0
        RX bytes:75930 (75.9 KB) TX bytes:71862 (71.8 KB)

      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      UP LOOPBACK RUNNING MTU:65536 Metric:1
      RX packets:8 errors:0 dropped:0 overruns:0 frame:0
      TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1
      RX bytes:711 (711.0 B) TX bytes:711 (711.0 B)

    6. On nginx container, ifconfig reveals the following -
      eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
      inet 172.18.0.3 netmask 255.255.0.0 broadcast 0.0.0.0
      ether 02:42:ac:12:00:03 txqueuelen 0 (Ethernet)
      RX packets 1311 bytes 355899 (347.5 KiB)
      RX errors 0 dropped 0 overruns 0 frame 0
      TX packets 1123 bytes 106391 (103.8 KiB)
      TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

     lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
         inet 127.0.0.1  netmask 255.0.0.0
         loop  txqueuelen 1  (Local Loopback)
         RX packets 64  bytes 7170 (7.0 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 64  bytes 7170 (7.0 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    1. curl output

      1. from inside the eth container -> curl 172.18.0.3, (the ip address of nginx webserver container from 2.2.2 above) reveals the nginx welcome html, so that works.
      2. from inside the nginx webserver container -> curl 172.18.0.2:8545 or curl 172.8.0.2:30303, (the ip address of eth container from 2.2.1 above) produces -> connection refused
    2. ping output

      1. Both containers are able to ping one another using the ip addresses mentioned above, but ping with hostname (from docker container inspect) or ping container name … fails.
      2. ping on containers are not accessible from the host command line fails
    3. browser output

      1. http://localhost brings up the nginx home page as documented

(Sreenivas Makam) #4

nginx container port 80 is exposed to port 9015 in your host. Not clear why http://localhost is giving you nginx page. http://localhost:9015 should give you nginx page.

Can you try http://localhost:8545 and http://30303 from your host machine to isolate if its a container<->container connectivity issue or container port connectivity issue.


(Vramana) #5

http://localhost:9015 should give you nginx page…
That is correct. My bad…

Can you try http://localhost:8545 and with 30303 from your host machine …
Yes, both of these do not work. Server not found error.


(Vramana) #6

info regarding Host Machine / Docker version / Docker inspect of the respective containers ->

  1. The host machine is win10 64-bit Enterprise. version.

2.Docker version ->
Client:
Version: 17.06.1-ce
API version: 1.30
Go version: go1.8.3
Git commit: 874a737
Built: Thu Aug 17 22:48:20 2017
OS/Arch: windows/amd64

Server:
Version: 17.06.1-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 874a737
Built: Thu Aug 17 22:54:55 2017
OS/Arch: linux/amd64
Experimental: false
Docker Inspect output for the container running Ethereum image

  1. docker inspect eth_poc_isolatednw (the container running Ethereum image)
    [
    {
    “Id”: “96b1cd515a2cf55a6539dcfb2a351e5112a041d41bad3350c36e3923f6b4e52e”,
    “Created”: “2017-08-29T14:22:13.1136367Z”,
    “Path”: “bash”,
    “Args”: [],
    “State”: {
    “Status”: “running”,
    “Running”: true,
    “Paused”: false,
    “Restarting”: false,
    “OOMKilled”: false,
    “Dead”: false,
    “Pid”: 26208,
    “ExitCode”: 0,
    “Error”: “”,
    “StartedAt”: “2017-08-29T16:56:16.5582456Z”,
    “FinishedAt”: “2017-08-29T15:49:22.3916662Z”
    },
    “Image”: “sha256:f2a539ec97b9bbe606c198a15364a91c44bd3c55827e6dadb3b1b7693f81aa84”,
    “ResolvConfPath”: “/var/lib/docker/containers/96b1cd515a2cf55a6539dcfb2a351e5112a041d41bad3350c36e3923f6b4e52e/resolv.conf”,
    “HostnamePath”: “/var/lib/docker/containers/96b1cd515a2cf55a6539dcfb2a351e5112a041d41bad3350c36e3923f6b4e52e/hostname”,
    “HostsPath”: “/var/lib/docker/containers/96b1cd515a2cf55a6539dcfb2a351e5112a041d41bad3350c36e3923f6b4e52e/hosts”,
    “LogPath”: “/var/lib/docker/containers/96b1cd515a2cf55a6539dcfb2a351e5112a041d41bad3350c36e3923f6b4e52e/96b1cd515a2cf55a6539dcfb2a351e5112a041d41bad3350c36e3923f6b4e52e-json.log”,
    “Name”: “/eth_poc_isolatednw”,
    “RestartCount”: 0,
    “Driver”: “overlay2”,
    “MountLabel”: “”,
    “ProcessLabel”: “”,
    “AppArmorProfile”: “”,
    “ExecIDs”: null,
    “HostConfig”: {
    “Binds”: null,
    “ContainerIDFile”: “”,
    “LogConfig”: {
    “Type”: “json-file”,
    “Config”: {}
    },
    “NetworkMode”: “isolated_nw”,
    “PortBindings”: {
    “30303/tcp”: [
    {
    “HostIp”: “”,
    “HostPort”: “30303”
    }
    ],
    “8545/tcp”: [
    {
    “HostIp”: “”,
    “HostPort”: “8545”
    }
    ]
    },
    “RestartPolicy”: {
    “Name”: “no”,
    “MaximumRetryCount”: 0
    },
    “AutoRemove”: false,
    “VolumeDriver”: “”,
    “VolumesFrom”: null,
    “CapAdd”: [
    “NET_ADMIN”
    ],
    “CapDrop”: null,
    “Dns”: [],
    “DnsOptions”: [],
    “DnsSearch”: [],
    “ExtraHosts”: null,
    “GroupAdd”: null,
    “IpcMode”: “”,
    “Cgroup”: “”,
    “Links”: null,
    “OomScoreAdj”: 0,
    “PidMode”: “”,
    “Privileged”: false,
    “PublishAllPorts”: false,
    “ReadonlyRootfs”: false,
    “SecurityOpt”: null,
    “UTSMode”: “”,
    “UsernsMode”: “”,
    “ShmSize”: 67108864,
    “Runtime”: “runc”,
    “ConsoleSize”: [
    52,
    157
    ],
    “Isolation”: “”,
    “CpuShares”: 0,
    “Memory”: 0,
    “NanoCpus”: 0,
    “CgroupParent”: “”,
    “BlkioWeight”: 0,
    “BlkioWeightDevice”: null,
    “BlkioDeviceReadBps”: null,
    “BlkioDeviceWriteBps”: null,
    “BlkioDeviceReadIOps”: null,
    “BlkioDeviceWriteIOps”: null,
    “CpuPeriod”: 0,
    “CpuQuota”: 0,
    “CpuRealtimePeriod”: 0,
    “CpuRealtimeRuntime”: 0,
    “CpusetCpus”: “”,
    “CpusetMems”: “”,
    “Devices”: [],
    “DeviceCgroupRules”: null,
    “DiskQuota”: 0,
    “KernelMemory”: 0,
    “MemoryReservation”: 0,
    “MemorySwap”: 0,
    “MemorySwappiness”: -1,
    “OomKillDisable”: false,
    “PidsLimit”: 0,
    “Ulimits”: null,
    “CpuCount”: 0,
    “CpuPercent”: 0,
    “IOMaximumIOps”: 0,
    “IOMaximumBandwidth”: 0
    },
    “GraphDriver”: {
    “Data”: {
    “LowerDir”: “/var/lib/docker/overlay2/53dd15212c6c66288077f61458482c3d4235887555251116770cc9b59ff1783e-init/diff:/var/lib/docker/overlay2/3d2ce752689061e8a40a4286b5f80aca6053ccfa7928db25c82b0a4adca85dce/diff:/var/lib/docker/overlay2/74db2389afac6e449ed39373728690de4878fcf1ade73e163c09ca9b2fa5367a/diff:/var/lib/docker/overlay2/a0bf95ab403a30a49f091e4c324eb78d73595454f051d485a38ddb4e30c89eda/diff:/var/lib/docker/overlay2/ca857f2730615337d279e8adfafe28fb8dad4d3f325cae3eafd9b76a827f701c/diff:/var/lib/docker/overlay2/3a88adb6825c3e6d7b31b43e3fc9672530bee62736e0fdb10ba9fd7c4357b8c5/diff:/var/lib/docker/overlay2/6e854b4d4994fe1876c65a6a344c2ad8295e8134d78b04baf36ea059f7db65d9/diff:/var/lib/docker/overlay2/e8beb7936206c17fe5a900dc5317c80fd3624e275110a7de09ca60b22621066b/diff:/var/lib/docker/overlay2/f4ab5bc40ecd025a3a32d761c8707c8d1293fea7c3b95a9680a6510bcdfb5dd7/diff”,
    “MergedDir”: “/var/lib/docker/overlay2/53dd15212c6c66288077f61458482c3d4235887555251116770cc9b59ff1783e/merged”,
    “UpperDir”: “/var/lib/docker/overlay2/53dd15212c6c66288077f61458482c3d4235887555251116770cc9b59ff1783e/diff”,
    “WorkDir”: “/var/lib/docker/overlay2/53dd15212c6c66288077f61458482c3d4235887555251116770cc9b59ff1783e/work”
    },
    “Name”: “overlay2”
    },
    “Mounts”: [],
    “Config”: {
    “Hostname”: “96b1cd515a2c”,
    “Domainname”: “”,
    “User”: “”,
    “AttachStdin”: true,
    “AttachStdout”: true,
    “AttachStderr”: true,
    “ExposedPorts”: {
    “30303/tcp”: {},
    “8545/tcp”: {}
    },
    “Tty”: true,
    “OpenStdin”: true,
    “StdinOnce”: true,
    “Env”: [
    “PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
    “DEBIAN_FRONTEND=noninteractive”
    ],
    “Cmd”: null,
    “Image”: “eth_setup_image”,
    “Volumes”: null,
    “WorkingDir”: “”,
    “Entrypoint”: [
    “bash”
    ],
    “OnBuild”: null,
    “Labels”: {}
    },
    “NetworkSettings”: {
    “Bridge”: “”,
    “SandboxID”: “096673c2d690258a4b02315bcf26af918a5471ee09f6dd6fa8b057319c9c5807”,
    “HairpinMode”: false,
    “LinkLocalIPv6Address”: “”,
    “LinkLocalIPv6PrefixLen”: 0,
    “Ports”: {
    “30303/tcp”: [
    {
    “HostIp”: “0.0.0.0”,
    “HostPort”: “30303”
    }
    ],
    “8545/tcp”: [
    {
    “HostIp”: “0.0.0.0”,
    “HostPort”: “8545”
    }
    ]
    },
    “SandboxKey”: “/var/run/docker/netns/096673c2d690”,
    “SecondaryIPAddresses”: null,
    “SecondaryIPv6Addresses”: null,
    “EndpointID”: “”,
    “Gateway”: “”,
    “GlobalIPv6Address”: “”,
    “GlobalIPv6PrefixLen”: 0,
    “IPAddress”: “”,
    “IPPrefixLen”: 0,
    “IPv6Gateway”: “”,
    “MacAddress”: “”,
    “Networks”: {
    “isolated_nw”: {
    “IPAMConfig”: null,
    “Links”: null,
    “Aliases”: [
    “96b1cd515a2c”
    ],
    “NetworkID”: “9ac37194c73f9abe91471e576ec6116eeb233d71f5328324517389437f81b98c”,
    “EndpointID”: “8386c423e5f8e915044cde8eb0e949fb050a9c5cf5e9e9a7e018fa4734c1eb10”,
    “Gateway”: “172.18.0.1”,
    “IPAddress”: “172.18.0.2”,
    “IPPrefixLen”: 16,
    “IPv6Gateway”: “”,
    “GlobalIPv6Address”: “”,
    “GlobalIPv6PrefixLen”: 0,
    “MacAddress”: “02:42:ac:12:00:02”,
    “DriverOpts”: null
    }
    }
    }
    }
    ]

  2. Docker inspect nginx-webserver_isolatednw ( the container running nginx webserver)

[
{
“Id”: “1d0cdc7f54bca26525d3140ef567520ae4132125bec15173bf9b4257fb12517e”,
“Created”: “2017-08-29T14:38:02.7915953Z”,
“Path”: “nginx”,
“Args”: [
"-g",
“daemon off;”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 6537,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2017-08-29T14:38:04.1527602Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
},
“Image”: “sha256:c255e2c119bef43039a4cea0bd1ba1bf30738c446fa8e68a29fba3ac38594cea”,
“ResolvConfPath”: “/var/lib/docker/containers/1d0cdc7f54bca26525d3140ef567520ae4132125bec15173bf9b4257fb12517e/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/1d0cdc7f54bca26525d3140ef567520ae4132125bec15173bf9b4257fb12517e/hostname”,
“HostsPath”: “/var/lib/docker/containers/1d0cdc7f54bca26525d3140ef567520ae4132125bec15173bf9b4257fb12517e/hosts”,
“LogPath”: “/var/lib/docker/containers/1d0cdc7f54bca26525d3140ef567520ae4132125bec15173bf9b4257fb12517e/1d0cdc7f54bca26525d3140ef567520ae4132125bec15173bf9b4257fb12517e-json.log”,
“Name”: “/nginx-webserver_isolated”,
“RestartCount”: 0,
“Driver”: “overlay2”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: null,
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “isolated_nw”,
“PortBindings”: {
“80/tcp”: [
{
“HostIp”: “”,
“HostPort”: “9015”
}
]
},
“RestartPolicy”: {
“Name”: “no”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: null,
“CapAdd”: [
“NET_ADMIN”
],
“CapDrop”: null,
“Dns”: [],
“DnsOptions”: [],
“DnsSearch”: [],
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
52,
157
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: [],
“DeviceCgroupRules”: null,
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: -1,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0
},
“GraphDriver”: {
“Data”: {
“LowerDir”: “/var/lib/docker/overlay2/8a31afa704c74fe305188597ff29ef74a1dc425270b879a5a1aa3845d8f903db-init/diff:/var/lib/docker/overlay2/8f8af070f847abda8d5eb9796bb9bb117cda39e494b262b66250b5a6f04cc37b/diff:/var/lib/docker/overlay2/dea0e6577530c50ff2fce5775b7aa41aa14b5f1e7de45c9b4d9f4de874d57824/diff:/var/lib/docker/overlay2/343e37fd2d73b958c4cc0a48bfa73c6fa464496eaba546bf71cd2740c9dce9c1/diff:/var/lib/docker/overlay2/917f9c686b47b9a573840491e658b29d87e8d58aa00426ec47bd85acd5116a33/diff”,
“MergedDir”: “/var/lib/docker/overlay2/8a31afa704c74fe305188597ff29ef74a1dc425270b879a5a1aa3845d8f903db/merged”,
“UpperDir”: “/var/lib/docker/overlay2/8a31afa704c74fe305188597ff29ef74a1dc425270b879a5a1aa3845d8f903db/diff”,
“WorkDir”: “/var/lib/docker/overlay2/8a31afa704c74fe305188597ff29ef74a1dc425270b879a5a1aa3845d8f903db/work”
},
“Name”: “overlay2”
},
“Mounts”: [],
“Config”: {
“Hostname”: “1d0cdc7f54bc”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“80/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“NGINX_VERSION=1.13.3-1~stretch”,
“NJS_VERSION=1.13.3.0.1.11-1~stretch”
],
“Cmd”: [
“nginx”,
"-g",
“daemon off;”
],
“ArgsEscaped”: true,
“Image”: “nginx_plus_changes”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {},
“StopSignal”: “SIGTERM”
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “7c3ac68e08f308676d8435677285e02cf71d56a4b0d9629ff3b5be5aa3d1b891”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {
“80/tcp”: [
{
“HostIp”: “0.0.0.0”,
“HostPort”: “9015”
}
]
},
“SandboxKey”: “/var/run/docker/netns/7c3ac68e08f3”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “”,
“Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “”,
“IPPrefixLen”: 0,
“IPv6Gateway”: “”,
“MacAddress”: “”,
“Networks”: {
“isolated_nw”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: [
“1d0cdc7f54bc”
],
“NetworkID”: “9ac37194c73f9abe91471e576ec6116eeb233d71f5328324517389437f81b98c”,
“EndpointID”: “5f9f659b51172a76d2c516dac3cab4a41fd8914b6501e6d959b48759be3f2e6b”,
“Gateway”: “172.18.0.1”,
“IPAddress”: “172.18.0.3”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:12:00:03”,
“DriverOpts”: null
}
}
}
}
]


(Sreenivas Makam) #7

I would start first debugging ethereum container to check why exposing port does not work. Since accessing this container from host machine also does not work, this looks more like the issue is specific to the container.


(Vramana) #8

Problem got resolved after running and installing xinetd daemon.


(RONNY FREITES V.) #9

hi, I had the same issue, I make a docker network inspect “YOUR_BRIDGE_NETWORK” and you will see the Gateway ip, please use “GATEWAY_PORT”:“CONTAINER_PORT” to communicate between containers