By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Gracefully shutting down containers without losing data or causing data corruption is achieved by using the docker stop command instead of docker kill.
docker run -d --name my-container my-image
docker ps -a
docker stop my-container
docker rm $(docker ps -aq -f status=exited)
docker rm my-container
-t
docker stop -t 10 my-container
docker stop -s SIGTERM my-container
-s
Error response from daemon: No such container: my-container
Error response from daemon: Cannot stop container my-container: Container my-container is not running
docker start my-container
Error response from daemon: Invalid signal: SIGUSR1
• docker stop vs docker kill: Use docker stop to stop a container gracefully, and docker kill to force-kill a container.• ⚠️ docker rm deletes all stopped containers: Use docker rm -f to force-remove a container.• docker stop -t specifies a timeout: Use docker stop -t 10 to stop a container within 10 seconds.• docker stop -s specifies a custom stop signal: Use docker stop -s SIGTERM to stop a container with a custom signal.• ⚠️ docker rm does not remove volumes: Use docker volume rm to remove volumes.• docker stop does not remove networks: Use docker network rm to remove networks.• ⚠️ docker rm does not remove images: Use docker rmi to remove images.• docker stop does not remove containers with mounted volumes: Use docker rm -f to force-remove containers with mounted volumes.• docker stop does not remove containers with running processes: Use docker rm -f to force-remove containers with running processes.• ⚠️ docker stop does not remove containers with attached shells: Use docker detach to detach from the shell before stopping the container.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.