Reputation: 21
Docker sometimes exists but still keeps running.
Started with :
docker run -v $PWD:/host --rm -it Ubuntu_2018
After "exit" : Docker container ls; docker container ls -al
This still shows container running How to make sure that docker container is gracefully ended?
Using the option "--rm"
and exiting the docker with "exit" should do the needful. But it still sometimes remains.
After exit, "docker container ls; docker container ls -al" should not show the docker at all
Upvotes: 2
Views: 727
Reputation: 1323065
How to ensure confirmed graceful exit of docker?
Not by looking at the docker container ls -al
output, which as commented shows the stopped containers.
But by looking at:
docker inspect -f '{{.State.ExitCode}}' <container SHA>
For that, see "Gracefully Stopping Docker Containers" by Brian DeHamer, who reminds us that When you use docker stop or docker kill to signal a container, that signal is sent only to the container process running as PID 1.
See also "Life and death of a container" from Luis Herrera Benítez who points out the existence of "docker inspect --format='{{.State.Health.Status}}' <containerName>
": if it is unhealthy... chances are your subsequent stop might not be graceful.
Upvotes: 1