Baseline costs of a Docker container

by Zebulun Arendsee

This is a minimal docker container example that wraps a standalone executable in a container. The container size is ~1MB and the runtime is ~1s.

Given a little C hello world program:

#include <stdio.h>

int main(int argc, char * argv[]){
    return 0;

Compile it with the static option that makes a standalone executable that is not dependent on the system’s dynamic libraries.

cc -static -o hello hello.c

Then write the Dockerfile that starts on the empty scratch image, loads the hello executable, and sets the container command to call the executable:

From scratch
Add hello .
CMD ["/hello"]

Build the container:

sudo docker build --tag hello .

Then check to see that it is in the image list, note the nice small size (less than a megabyte). Also note that the size of the hello executable makes up the bulk of the size, the container only adds a few kilobytes.

sudo docker image ls

Then to run the container:

sudo docker run hello

On my system, there is about a 1 second delay. This is the constant cost of running a docker container.