Exercise · 6 steps · about 10 minutes
Docker: try it yourself¶
Build the status page app from the video into an image, from nothing but its own files, and run it with Docker. Then look inside its container, row by row, and watch Linux stop it at its 64 MB limit.
You need Git and Docker (start Docker Desktop first, or the Docker service on Linux), about 1 GB of free disk space and ports 8080 and 8082 free on 127.0.0.1. Run the commands in a terminal: Terminal on a Mac, your shell on Linux, and on Windows a WSL terminal, such as Ubuntu, with Docker Desktop's WSL integration turned on. On Linux, put sudo in front of docker unless you are in the docker group.
The card from the video: what you check in step 4
its own root folder, from the image
the app is process 1
its own address
64 MB and half a CPU
10001, not root
1. Collect the app's files¶
Get the exercise from my tutorials repository on GitHub:
git clone --depth 1 --branch 284-docker-explained https://github.com/antonputra/tutorials.git
cd tutorials/lessons/284
The folder has the app from the video, app/status.py and app/message.txt, and two Dockerfiles. The app is a small status page in Python: on each request, it reads message.txt, adds a line to /data/requests.log and sends the message back.
In the video, the app fails in an empty folder until the folder has Python, its loader and libraries, and Python's own code. Then I pack those files into python-files.tar. Here, a Docker build runs the same copy commands in an Ubuntu 26.04 container and saves the archive in this folder:
The first build downloads Ubuntu and Python, about 80 MB, so give it a minute. The archive is about 40 MB.
2. Build the image¶
The video's recipe is five lines:
FROM scratch
ADD python-files.tar /
COPY app/ /app/
USER 10001:10001
CMD ["python3", "/app/status.py", "--listen", "0.0.0.0"]
FROM scratch means no base image: the image starts empty, like the folder in the video. Build it, and look at its layers:
IMAGE CREATED CREATED BY SIZE COMMENT
aa881b01a05c 1 second ago CMD ["python3" "/app/status.py" "--listen" "… 0B buildkit.dockerfile.v0
<missing> 1 second ago USER 10001:10001 0B buildkit.dockerfile.v0
<missing> 1 second ago COPY app/ /app/ # buildkit 16.4kB buildkit.dockerfile.v0
<missing> 1 second ago ADD python-files.tar / # buildkit 45.3MB buildkit.dockerfile.v0
The newest line is on top. The two lines that add files are the layers: Python's files, about 45 MB, and our app. The other two only set the user and the start command.
3. Run it¶
The same docker run as in the video: a name, a memory limit, half a CPU, a port on 127.0.0.1 and a volume for the log:
docker run -d --name status --memory 64m --cpus 0.5 -p 127.0.0.1:8080:8000 -v status-data:/data status:1.0
It prints the new container's ID. Now ask for the page:
The app prints one line for each request, with the time in UTC:
You can open http://127.0.0.1:8080/status in your browser too.
4. Look inside¶
Now ask the container itself, one row of the card at a time. Its files are the image's, with dev, etc and sys added by Docker:
On an Intel or AMD computer, you see lib64 in place of lib. It has its own list of processes, and our app is process 1:
It has its own network, with its own address:
2: eth0@if8: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 16:d7:56:d3:c4:10 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
Its limits are two files of its control group:
That's 64 MB in bytes, and 50 ms of CPU time in every 100 ms: half a CPU. Last, its user, with none of root's powers:
5. Hit the limit¶
The app has a bug switch from the video: with --leak-mb 10, it keeps 10 MB more on every request and never gives it back. Start a second container from the same image with the leak on (the command after the image name replaces its start command):
docker run -d --name leaky --memory 64m --memory-swap 64m -p 127.0.0.1:8082:8000 status:1.0 python3 /app/status.py --listen 0.0.0.0 --leak-mb 10
Then send it eight requests:
for i in 1 2 3 4 5 6 7 8; do curl -s -o /dev/null -w "request $i: HTTP %{http_code}\n" -m 5 http://127.0.0.1:8082/status; done
request 1: HTTP 200
request 2: HTTP 200
request 3: HTTP 200
request 4: HTTP 200
request 5: HTTP 200
request 6: HTTP 000
request 7: HTTP 000
request 8: HTTP 000
Five answers, then nothing. At request 6, the app needed more than 64 MB, and Linux killed it. Docker shows how it ended:
137 means killed by force. Linux does that to a process when its group needs more memory than the limit: an OOM kill, for out of memory. --memory-swap 64m keeps swap out of it. The server in the video has no swap, but Docker Desktop's VM has some, and without the flag Docker lets the app use 64 MB of swap on top: on my test machine, it answered 11 requests.
Extra: a new container, the same data¶
Change the message inside the running container, as root, then remove the container and run a new one from the same image:
docker exec --user 0 status sh -c 'echo "Status: MAINTENANCE" > /app/message.txt'
curl http://127.0.0.1:8080/status
docker rm -f status
docker run -d --name status --memory 64m --cpus 0.5 -p 127.0.0.1:8080:8000 -v status-data:/data status:1.0
Ask the new container for the page, and read the log:
2026-11-19T19:35:41Z 172.17.0.1 GET /status
2026-11-19T19:35:42Z 172.17.0.1 GET /status
2026-11-19T19:35:42Z 172.17.0.1 GET /status
The change lived in the old container's own top layer, so the new container says Status: OK again. The log is in the volume, so it still has the old container's lines, with the new one's last.
6. Clean up¶
The builds also keep about 500 MB of cache, Ubuntu and Python included. To free it, run docker builder prune -f: it clears the cache of your other Docker builds too. Then you can delete the tutorials folder: cd ../../.. && rm -rf tutorials.
The full lab¶
In the video, I build this container by hand first, with plain Linux commands, before Docker is even installed. The full lab does every step of it on a Linux server of your own, a free VM, then builds the same container with Docker and opens it to compare.
Free. Unsubscribe anytime. Form not loading? Subscribe here.