79553489

Date: 2025-04-03 16:25:34
Score: 0.5
Natty:
Report link

I would like to refer to this article, which explains it shortly but clearly. The Docker CLI actually sets two attributes (in two requests) to achieve the desired result of the one -p PORT option.

So, you not only need to specify the "ExposedPorts" attribute in the /containers/create request, but also the "PortBindings" attribute in the /containers/{id}/start request as follows:

{
    "id": id,
    "PortBindings": {
        "container_port/tcp": [
            {
                 "HostIp": "host_ip", // Strings, not numbers here
                 "HostPort": "host_port"
            }
        ]
    }
}

Don't forget/oversee the square brackets as in David Maze's answer.

Reasons:
  • Blacklisted phrase (1): this article
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Christoph Derszteler