0

reading the doc from docker remote api I get issue when start my container using the API https://docs.docker.com/engine/api/v1.41/#operation/ContainerCreate

The doc at the "Publish or expose port (-p, --expose)" section talks about use the -p to bind a port to application. Using the docker remote api I create the container using this payload

    POST http://[...]/containers/create

    {
        "Image": "correiosimg",
        "ExposedPorts":{
            "0.0.0.0:80:8089/tcp":{}
        }
    }

but when I call the endpoint to start the container, It takes the port "0/tcp" on docker console.. the service starts, but inacessible

my docker ps console: https://i.stack.imgur.com/V53Mc.png docker compose file: https://i.stack.imgur.com/ueC2f.png

tkss!

  • I'm not sure why `docker ps` would write out a PNG file, and I know `docker-compose` doesn't accept one. I think the question you've asked is clear enough without these details, but do make sure you've included source code and program outputs directly in the question (not behind links) and as text (not screen shots). – David Maze May 01 '22 at 10:03

1 Answers1

0

The setting you show is for the essentially meaningless "expose" option. You need to "publish" ports instead. That operation is in "HostConfig" "PortBindings"; it is an object with the container ports as keys and a small object with values.

So the API request body you need might look a little more like

{
  "Image": "correiosimg",
  "HostConfig": {
    "PortBindings": {
      "8089/tcp": {
        "HostIp": "0.0.0.0",
        "HostPort": "80"
      }
    }
  }
}
David Maze
  • 130,717
  • 29
  • 175
  • 215