Binding a port to a host interface using the REST API

Starting containers with PortBindings in the HostConfig was deprecated in v1.10 and removed in v1.12.

Both these configuration parameters should now be included when creating the container.

POST /containers/create

{
    "Image": image_id,
    "ExposedPorts": {
        "22/tcp": {}
    },
    "HostConfig": {
        "PortBindings": { "22/tcp": [{ "HostPort": "" }] }
    }
}

This is an undocumented feature. I found my answer on the mailing list:

When creating the container you have to set ExposedPorts:

"ExposedPorts": { "22/tcp": {} }

When starting your container you need to set PortBindings:

"PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }

There already is an issue on github about this.

Tags:

Docker