What is the most appropriate (smallest, simplest) container to use for a data only Docker container?
In the documentation they use the training/postgres container. Howe
I recommend the tianon/true image from this collection of dockerfiles. At 125 Byte, It is smaller than busybox based images:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tianon/true latest 724d63a6172d 35 hours ago 125 B
A container based on this image exits immediately which is appropriate for a storage only container.
Update: Now that we have named volumes, you generally don't want to use data containers at all.
Use the same image for the data container - in this case the Postgres image. You don't leave data containers running, so it won't consume resources.
Using the same image is important for several reasons:
For more information see Data Only Container Madness.
Busybox is a base image, not a user image, and thus a little more practical for production use, it is also tiny.
The image docker page here
BusyBox: The Swiss Army Knife of Embedded Linux
At about 2.5 Mb in size. Busybox is one of the smallest Linux distribution available.
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system.
This post recommends using an empty "scratch" container - no OS at all:
Dockerfile:
FROM scratch
VOLUME /data
ENTRYPOINT ["/no/such/file"]
I just made an empty one, and the image is... 0 bytes!
Then I COPY'd just a 2k file in during build, and the image is 260 bytes, so must be compressed.
I am using this because named volumes aren't so useful in semi/serverless environments like AWS Fargate where is no host, and you want to deploy versioned data.
Update: if you want the container to work correctly in docker-compose the above example won't work because the entrypoint fails. tianon/true
seems to be the best solution, a tiny program which returns true. So you can use FROM tianon/true
.