Skip to content

Instantly share code, notes, and snippets.

@apatil
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apatil/dee124fd868871f18cb7 to your computer and use it in GitHub Desktop.
Save apatil/dee124fd868871f18cb7 to your computer and use it in GitHub Desktop.
How to get Docker to choose the ports using the remote API?
curl -v -H "Content-Type: application/json" -X POST \
-d '{"Cmd":["/bin/sleep","infinity"],"Image":"ubuntu:14.04", "ExposedPorts":{"22/tcp":{}}}' \
http://127.0.0.1:4243/containers/create?name=testcontainer
curl -v -H "Content-Type: application/json" -X POST \
-d '{"PortBindings": { "22/tcp": [{ "HostPort": "11022" }]} }' \
http://127.0.0.1:4243/containers/testcontainer/start
@apatil
Copy link
Author

apatil commented Jul 25, 2014

Answer:

curl -v -H "Content-Type: application/json" -X POST -d '{"Cmd":["/bin/sleep","infinity"],"Image":"ubuntu:14.04", "ExposedPorts":{"22/tcp":{}}}'  http://127.0.0.1:4243/containers/create?name=testcontainer

curl -v -H "Content-Type: application/json" -X POST -d '{"PublishAllPorts": true}' http://127.0.0.1:4243/containers/testcontainer/start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment