title: Publish docker container port and access that port from another docker container
body: <p>I'm trying to run a <a href="https://hub.docker.com/_/postgres/" rel="nofollow noreferrer" title="postgres docker">postgres container</a> with docker and access to it from another container.
  Steps to reproduce:</p>
  
  <ul>
  <li><p>Run postgres container and publish port: <code>docker run -e POSTGRES_PASSWORD=test -d -p 5555:5432 postgres:9.6
  </code> </p></li>
  <li><p>Run other container to access to the postgres:
  <code>
  docker run -it debian /bin/bash
  apt-get update
  apt-get install telnet
  telnet 172.17.0.1 5555
  </code></p></li>
  </ul>
  
  <p>Result: <code>Trying 172.17.0.1...</code> and then fail.
  But i can access it from the host with localhost or from outside with the public ip because the image allow all ip, and i am not blocking that port.
  The ping works.</p>
  
  <p>I have tested this in my machine and it works as expected, but i need to know why it is not working on this server.</p>
  
  <p>Where can i start looking to know what i have wrong on my server?</p>
  
  <p><strong>Update:</strong>
  I tried doing the telnet directly to the ip asigned to the postgres container(172.17.0.2) and i get the following error:
  <code>
  telnet 172.17.0.2
  Trying 172.17.0.2...
  telnet: Unable to connect to remote host: Connection refused
  </code>
  But ping still works at 172.17.0.2</p>
  
  <p>Output of docker inspect on the postgres container:</p>
  
  <pre><code>docker inspect a379130e94f7
  [
      {
          "Id": "a379130e94f7596ebe632e3ae825710c978577a3fb6b245a4f95374051eb8310",
          "Created": "2017-03-31T08:07:36.06939775Z",
          "Path": "docker-entrypoint.sh",
          "Args": [
              "postgres"
          ],
          "State": {
              "Status": "running",
              "Running": true,
              "Paused": false,
              "Restarting": false,
              "OOMKilled": false,
              "Dead": false,
              "Pid": 20283,
              "ExitCode": 0,
              "Error": "",
              "StartedAt": "2017-03-31T08:07:37.257557864Z",
              "FinishedAt": "0001-01-01T00:00:00Z"
          },
          "Image": "sha256:9910dc9f2ac0dbc193abc4718984cb3ad48989fc02cac4b36ad3d6b7d5d781f9",
          "ResolvConfPath": "/var/lib/docker/containers/a379130e94f7596ebe632e3ae825710c978577a3fb6b245a4f95374051eb8310/resolv.conf",
          "HostnamePath": "/var/lib/docker/containers/a379130e94f7596ebe632e3ae825710c978577a3fb6b245a4f95374051eb8310/hostname",
          "HostsPath": "/var/lib/docker/containers/a379130e94f7596ebe632e3ae825710c978577a3fb6b245a4f95374051eb8310/hosts",
          "LogPath": "/var/lib/docker/containers/a379130e94f7596ebe632e3ae825710c978577a3fb6b245a4f95374051eb8310/a379130e94f7596ebe632e3ae825710c978577a3fb6b245a4f95374051eb8310-json.log",
          "Name": "/gallant_thompson",
          "RestartCount": 0,
          "Driver": "overlay",
          "MountLabel": "",
          "ProcessLabel": "",
          "AppArmorProfile": "",
          "ExecIDs": null,
          "HostConfig": {
              "Binds": null,
              "ContainerIDFile": "",
              "LogConfig": {
                  "Type": "json-file",
                  "Config": {}
              },
              "NetworkMode": "default",
              "PortBindings": {
                  "5432/tcp": [
                      {
                          "HostIp": "",
                          "HostPort": "5555"
                      }
                  ]
              },
              "RestartPolicy": {
                  "Name": "no",
                  "MaximumRetryCount": 0
              },
              "AutoRemove": false,
              "VolumeDriver": "",
              "VolumesFrom": null,
              "CapAdd": null,
              "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": [
                  0,
                  0
              ],
              "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": [],
              "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": {
              "Name": "overlay",
              "Data": {
                  "LowerDir": "/var/lib/docker/overlay/34f43052282b0bcba741b61cb812bc4e05d1d0045820c36781684e2f2f763b41/root",
                  "MergedDir": "/var/lib/docker/overlay/904ec813189c55332d8cb5ee3dca74e211a0d42a4434f8a90e07b8a05f4d5c5b/merged",
                  "UpperDir": "/var/lib/docker/overlay/904ec813189c55332d8cb5ee3dca74e211a0d42a4434f8a90e07b8a05f4d5c5b/upper",
                  "WorkDir": "/var/lib/docker/overlay/904ec813189c55332d8cb5ee3dca74e211a0d42a4434f8a90e07b8a05f4d5c5b/work"
              }
          },
          "Mounts": [
              {
                  "Type": "volume",
                  "Name": "82dd5d73415e8142eb5bb985a9695f46772328f271ede839cbf55436917ed120",
                  "Source": "/var/lib/docker/volumes/82dd5d73415e8142eb5bb985a9695f46772328f271ede839cbf55436917ed120/_data",
                  "Destination": "/var/lib/postgresql/data",
                  "Driver": "local",
                  "Mode": "",
                  "RW": true,
                  "Propagation": ""
              }
          ],
          "Config": {
              "Hostname": "a379130e94f7",
              "Domainname": "",
              "User": "",
              "AttachStdin": false,
              "AttachStdout": false,
              "AttachStderr": false,
              "ExposedPorts": {
                  "5432/tcp": {}
              },
              "Tty": false,
              "OpenStdin": false,
              "StdinOnce": false,
              "Env": [
                  "POSTGRES_PASSWORD=test",
                  "PATH=/usr/lib/postgresql/9.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                  "GOSU_VERSION=1.7",
                  "LANG=en_US.utf8",
                  "PG_MAJOR=9.6",
                  "PG_VERSION=9.6.2-1.pgdg80+1",
                  "PGDATA=/var/lib/postgresql/data"
              ],
              "Cmd": [
                  "postgres"
              ],
              "ArgsEscaped": true,
              "Image": "postgres:9.6",
              "Volumes": {
                  "/var/lib/postgresql/data": {}
              },
              "WorkingDir": "",
              "Entrypoint": [
                  "docker-entrypoint.sh"
              ],
              "OnBuild": null,
              "Labels": {}
          },
          "NetworkSettings": {
              "Bridge": "",
              "SandboxID": "55c678dffab73ca25857667ddb003751494d32beb917abd1bba4d77f61071d9f",
              "HairpinMode": false,
              "LinkLocalIPv6Address": "",
              "LinkLocalIPv6PrefixLen": 0,
              "Ports": {
                  "5432/tcp": [
                      {
                          "HostIp": "0.0.0.0",
                          "HostPort": "5555"
                      }
                  ]
              },
              "SandboxKey": "/var/run/docker/netns/55c678dffab7",
              "SecondaryIPAddresses": null,
              "SecondaryIPv6Addresses": null,
              "EndpointID": "a0f845fa572fd6b15fc7c2ba74d3a302eb353e51ddbafb97d81e8858124808d7",
              "Gateway": "172.17.0.1",
              "GlobalIPv6Address": "",
              "GlobalIPv6PrefixLen": 0,
              "IPAddress": "172.17.0.2",
              "IPPrefixLen": 16,
              "IPv6Gateway": "",
              "MacAddress": "02:42:ac:11:00:02",
              "Networks": {
                  "bridge": {
                      "IPAMConfig": null,
                      "Links": null,
                      "Aliases": null,
                      "NetworkID": "16d30671a47d90037673ef30843421eaeeeba41028ec204a8fcea13ac8108f6d",
                      "EndpointID": "a0f845fa572fd6b15fc7c2ba74d3a302eb353e51ddbafb97d81e8858124808d7",
                      "Gateway": "172.17.0.1",
                      "IPAddress": "172.17.0.2",
                      "IPPrefixLen": 16,
                      "IPv6Gateway": "",
                      "GlobalIPv6Address": "",
                      "GlobalIPv6PrefixLen": 0,
                      "MacAddress": "02:42:ac:11:00:02"
                  }
              }
          }
      }
  ]
  </code></pre>