-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
Docker does not (currently as of v1.5) allows a user to run a new command in a stopped container.
If the container is running, we can
- use
docker execto spawn a new command in the container from the host - use
docker attachornsenterto "enter" the container and manually run a command
If the container is stopped, we can
- use
docker startto restart the container with the same command used to launch it (viadocker run,docker create, or as specified by the Dockerfile instructionCMDorENTRYPOINT). docker restartworks the same way asdocker startexcept for a running container.
The use case would be to start a shell to debug the log files and other state on the disk after the process has crashed. (Or to explore a data-only container.)
See https://github.com/jpetazzo/nsenter/issues/27, moby/moby#1437, moby/moby#1228
Explanation
Containers should be ephemeral
The container produced by the image your Dockerfile defines should be as ephemeral as possible. By “ephemeral,” we mean that it can be stopped and destroyed and a new one built and put in place with an absolute minimum of set-up and configuration.
https://docs.docker.com/articles/dockerfile_best-practices/
Solution
All the container state (data, logging) that requires persistence MUST be stored outside the container's main layer.
- For the data, we should be using the Dockerfile instruction "VOLUME"
- For the logging, we need to explore solutions.