Docker remote API: “My containers won’t stay started”

If your containers work just fine when started through the CLI but exit immediately when started through the remote API, this may be for you. A common Dockerfile pattern for keeping service containers running is to start the services and then start something that waits for input on stdin, like bash:

CMD /bin/ && /bin/bash

This works for the CLI, but if you don’t explicitly open stdin with the remote API then bash will exit immediately and the container will stop. To open stdin, include the OpenStdin parameter in your container creation call:

POST /containers/create
"OpenStdin": true

Full docs

Senior Software Development Engineer @ Amazon. Trumpet player, drum corps enthusiast.