Linux Labs

Containers: Docker and compose / Stage 10 of 11

Limits, OOMKilled and the user in a container

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 9 · on a machine · 4 min

The report broke off

What you will learn

  • Recognise a memory shortage by code 137, OOMKilled and the kernel log, and set a limit with --memory.
  • Read container usage in docker stats and limit the CPU with the --cpus option.
  • Run a container's process as the right user with --user UID:GID.

Every night the report container builds a sales summary from ~/report-lab/sales.csv. This morning there is no summary, and not a single error email in the inbox. Look at how the container ended.

Exercise · look

See how the report ended

~/report-lab holds the nightly report: the report container builds a summary from sales.csv. Look at the list of containers, the report log and two fields from docker inspect.

First, predict

The report build did not finish. What will docker logs report show after the line about the build?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

The build broke off without an error message, the container exited with code 137, and OOMKilled is true. What stopped the build?

  • build.sh has no exit, and it printed no error. Code 137 is what a process gets when it is killed from outside by SIGKILL.

  • A container has no time limit: it is stopped with docker stop, and then OOMKilled stays false.

The kernel killed the build: it ran out of the memory given to the container.

Ubuntu 24.04
Loading…