As part of my deployment strategy, I am managing Docker containers with Upstart.
To do that, I need to pull an image from a registry and create a named container (as suggested on Upstart script to run container won't manage lifecycle )
Is there a way to create the container without first running the image? I don't want to have to start a container (which may introduce side effects), stop it, and then manage elsewhere.
For example, something like:
docker.io create -e ENV1=a -e ENV2=b -p 80:80 --name my_first_container sample/containe
You can achieve that by using Docker Remote API.
First of all adjust how docker daemon is running. Configure it to listen to HTTP requests on port 4243 in addition to the default unix socket:
Now, you can use the
/containers/create
endpoint to create a container without running it:Pay attention to the
?name=my_first_container
parameter I added to the curl request url. This is how you name your container.Side note - The same can be achieved without adding the HTTP interface, however it seems easier to show the solution using a simple curl POST request.
In case anyone else comes across this question, it can now be done with the
docker create
command. See https://docs.docker.com/engine/reference/commandline/create/