Reputation: 1125
I'm using Docker 1.9.1's remote API to create a container.
One thing I'm trying to accomplish is that among all the exposed ports of an image, I only want to expose a few of them (or in other words give them host port mapping), at the same time I don't want to manage the host ports to use but want Docker to pick up random and available ones.
For example, an image has port 80, 443, 22 exposed, what I want is something like this in a Docker run flavor (I know this is not possible through cmd line though)
docker run -p {a random available port}:80 image
Can I achieve something like this through remote API? Right now I can only set PublishAllPorts = true
but that publish all ports and waste too many host ports.
Upvotes: 1
Views: 2403
Reputation: 8401
Docker rest api for starting container allows you to define port bindings. For random mapping to host port use "PortBindings": { "80/tcp": [{ "HostPort": "" }] }
Upvotes: 3