By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Understanding exit codes helps diagnose and troubleshoot issues with Docker containers. docker run -it --rm.
docker --version
docker run -it --rm alpine /bin/echo "Hello World"
echo $?
docker container prune
docker run -it --rm alpine /bin/false
docker run -it --rm alpine /bin/sh -c "exit 125"
Purpose: Run a container with a specific exit code. Command: docker run -it --rm alpine /bin/sh -c "exit 125" Brief explanation of flags: -it runs the container in interactive mode, --rm removes the container when it exits.
-it
--rm
Purpose: Run a container with a non-zero exit code. Command: docker run -it --rm alpine /bin/false Brief explanation of flags: Same as above.
Purpose: Run a container with a zero exit code. Command: docker run -it --rm alpine /bin/echo "Hello World" Brief explanation of flags: Same as above.
Error message or symptom: docker: Error response from daemon: Container command 'exit 125' exited with code 125. Why it happens: The container exits with the specified code. One-line fix: docker run -it --rm alpine /bin/sh -c "exit 0"
docker: Error response from daemon: Container command 'exit 125' exited with code 125.
docker run -it --rm alpine /bin/sh -c "exit 0"
Error message or symptom: docker: Error response from daemon: Container command '/bin/false' exited with code 1. Why it happens: The container exits with a non-zero code. One-line fix: docker run -it --rm alpine /bin/echo "Hello World"
docker: Error response from daemon: Container command '/bin/false' exited with code 1.
Error message or symptom: docker: Error response from daemon: Container command '/bin/sh -c exit 125' exited with code 125. Why it happens: The container exits with the specified code. One-line fix: docker run -it --rm alpine /bin/sh -c "exit 0"
docker: Error response from daemon: Container command '/bin/sh -c exit 125' exited with code 125.
Situation: Container exits with code 0. Command to run: docker run -it --rm alpine /bin/echo "Hello World" What a correct response looks like: 0
0
Situation: Container exits with code 1. Command to run: docker run -it --rm alpine /bin/false What a correct response looks like: 1
1
Situation: Container exits with code 125. Command to run: docker run -it --rm alpine /bin/sh -c "exit 125" What a correct response looks like: 125
125
• Docker exit codes are based on the container's exit status.• Exit code 0 means the container exited successfully.• Exit code 1 means the container exited with a non-zero status.• Exit code 125 means the container was killed by a signal.• Exit code 126 means the container was killed by a signal due to a missing command.• Exit code 127 means the container was killed by a signal due to a command not found.• Exit code 128+n means the container was killed by a signal with number n.• Exit code 137 means the container was killed due to a timeout.• Exit code 143 means the container was killed due to a SIGTERM signal.• ⚠️ Always check the Docker version with docker version to ensure compatibility.• ⚠️ Use docker container prune to delete all stopped containers.• ⚠️ Use docker system prune to delete all unused data.
docker version
docker system prune
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.