One of my unit tests kills a running Docker container. For the unit test to work, I need to start up a container with docker-compose run
, such that it has something to kill.
What is the smallest and simplest image that can be used with a docker-compose.yml to make this happen?
Note that a Dockerfile isn’t required.
3
Answers
You just need a docker-compose file for that
You can probably find other images to run if you prefer something else.
nginx:alpine
springs to mind. That doesn’t need a command, so you’d save a line in the docker-compose file.If you’re looking for literally the very smallest image, and it literally needs to do nothing other than not exit,
k8s.gcr.io/pause
should be close.This image is part of Kubernetes and you can read its source. The Makefile compiles a small C program into a static binary, and then builds that into a
FROM scratch
image. That means it doesn’t even spend the megabyte for the BusyBox static binary, so it doesn’t contain unnecessary fluff like a shell,tail
, Alpine’sapk
package manager, or anything else at all.The one thing this image does other than sleep forever is to notice if any child processes exit and wait(2) for them. Since it expects to be process ID 1, this cleans up any orphaned processes that get reparented to the init process (euphemistically, "reaping zombies"). Kubernetes uses this as the root for a multi-container pod where the pods share various namespaces; also see What work does the process in container "gcr.io/google_containers/pause:0.8.0" do? or Ian Lewis’s The Almighty Pause Container (which includes the entire C source code as part of a blog post).
You could probably build an even smaller image if you rewrote the binary in assembly so you didn’t need the standard boilerplate to start and stop a C process, but it’s probably not worth the effort.
FWIW, I’ve found running
tail -f /dev/null
in busybox to be smaller in memory than pause. According to grafana, busybox uses about 216KiB; pause uses 616KiB.