Lesson 2 · Unit 04
Debugging containers
Why it exited: exit codes, logs, inspect, exec and memory limits
What you practise
- A container that exits at once, exit codes (137 and the memory limit),
logs,inspect,exec, resource limits
Try a question from this lesson
Pick one
docker run -d shop/api prints a container ID, but a moment later docker ps lists nothing. A container lives exactly as long as its main process. What happened?
Correct answer
The main process ended, so the container stopped
Why
docker ps lists running containers. This one started, its process ended (crashed or simply finished), and the container stopped with it. It still exists: docker ps -a shows it, with its exit code.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
First look: status and logs
When the main process ends, the container stops and Docker records the exit code.
docker ps -a lists stopped containers too, with the code in brackets. docker logs prints everything the process wrote, even after it has exited. Those two answer most questions.
$ docker ps -a
NAMES STATUS
api Exited (1) 5 seconds ago
$ docker logs api
KeyError: 'DB_HOST'Concept
Reading exit codes
The exit code says how the main process ended.
A code above 128 means a signal ended it: subtract 128 to get the signal number. 137 is signal 9, SIGKILL. 143 is signal 15, SIGTERM.
0 finished without error
1 the app reported an error
127 command not found
137 128 + 9, killed by SIGKILL
143 128 + 15, ended by SIGTERM10 more exercises in the app
- 2× type the answer
- 4× multiple choice
- 1× fill the blanks
- 1× true or false
- 1× match the pairs
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.