Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Troubleshooting Understanding Exit Codes 0 1 125 126 127 128n 137 143
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-troubleshooting-understanding-exit-codes-0-1-125-126-127-128n-137-143

Docker Docker Troubleshooting Understanding Exit Codes 0 1 125 126 127 128n 137 143

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~3 min read

1. Core Command / Concept

Understanding exit codes helps diagnose and troubleshoot issues with Docker containers. docker run -it --rm.

2. Step-by-Step

  1. Check the Docker version: docker --version
  2. Run a simple container with an exit code: docker run -it --rm alpine /bin/echo "Hello World"
  3. Check the exit code: echo $?
  4. ⚠️ Delete all stopped containers: docker container prune
  5. Run a container with a non-zero exit code: docker run -it --rm alpine /bin/false
  6. Check the exit code: echo $?
  7. Run a container with a specific exit code: docker run -it --rm alpine /bin/sh -c "exit 125"
  8. Check the exit code: echo $?

3. Real Commands with Examples

  1. 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.

  2. 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.

  3. 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.

4. Common Errors

  1. 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"

  2. 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"

  3. 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"

5. Quick Checks

  1. 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

  2. Situation: Container exits with code 1.
    Command to run: docker run -it --rm alpine /bin/false
    What a correct response looks like: 1

  3. 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

6. Last-Minute Reference

• 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.




ADVERTISEMENT