Search code examples
linuxdockerdocker-machinerhel7

Understanding docker port mappings


Please explain the following output:

docker ps ExanpleContainter

Ports
--------
10.10.10.10:443->443/tcp, 0.0.0.0:1937->1937/tcp

And, docker inspect ExanpleContainter

"Ports": {
  "1937/tcp": [
    {
      "HostIp": "0.0.0.0",
      "HostPort": "1937"
    }
  ],
  "443/tcp": [
    {
      "HostIp": "10.10.10.10",
      "HostPort": "443"
    }
  ]
}

I'd want to understand how mapping is done and which port is mapped where?


Solution

  • 10.10.10.10:443->443/tcp

    This means docker host IP 10.10.10.10 on port 443 is mapped to specified container on port 443. packets arriving at that ip port combination will be accessible in the container on the same port (443)

    0.0.0.0:1937->1937/tcp

    Packets arriving on all available IP addresses (0.0.0.0) on docker host on port 1937 are accessible on specified container on the same port (1937)

    Read explanation in the answer and compare it to output of docker inspect ExanpleContainter.