docker remote api cannot bind a port to a host

I was trying to use docker‘s remote api to bind a host, but it always fails.

I pass this dict using python and urllib2:

  • Why is the loop-lvm device storage not suitable for production?
  • Docker Ubuntu instance not connecting to the network
  • AWS EC2 ELB Docker Routing
  • Docker Access to Raspberry Pi GPIO Pins
  • Why does `apt install postgresql` not work in a docker container?
  • How Spring Cloud relates to Docker Swarm
  • {
        'Tty':True,
        'Volumes':[],
        'Image':'ubuntu',
        'Cmd':'',
        'WorkingDir':None,
        'Entrypoint':None,
        'Env':None,
        'AttachStdin':False,
        'AttachStdout':True,
        'AttachStderr':True,
        'OpenStdin':True,
        'ExposedPorts':{'80/tcp':{}},
        'HostConfig':{'PortBindings':{'80/tcp':['15080']}}
    }
    

    Then I use remote api to inspect container, it gives me the following:

    "NetworkSettings":{
        "Bridge":"docker0",
        "Gateway":"172.17.42.1",
        "IPAddress":"172.17.0.48",
        "IPPrefixLen":16,
        "PortMapping":null,
        "Ports":{"22/tcp":null,"80/tcp":null}
    }
    

    I also tried to use the method in this link Binding a port to a host interface using the REST API,
    but when I posted data to start the container, it will raise HTTP Error 500. So I guess whether the docker remote api had been changed.

  • Gitlab Pipelines Stages take hours or days to show result (passed, failed) - docker, node app
  • Unable to connect Vagrant machine to bridged network
  • What's the difference between “docker stop” and “docker rm”?
  • How do I connect to gcloud sql with gcloud sql proxy from GKE
  • docker suspend and resume using criu
  • Docker-compose: get linked container adress inside other container (in bash)
  • One Solution collect form web for “docker remote api cannot bind a port to a host”

    Looks like your PortBindings parameter is slightly off. You’re missing "HostPort":

    Change it to:

    'HostConfig':{'PortBindings':{'80/tcp':[{ "HostPort": '15080' }] }}
    

    From the docs:

    • PortBindings – A map of exposed container ports and the host port they should map to. It should be specified in the form {
      <port>/<protocol>: [{ “HostPort”: “<port>” }] } Take note that port
      is specified as a string and not an integer value.
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.