Pages

Wednesday, 10 February 2021

The minimum container image in the whole world!

 1. All files needed

$ ls
Dockerfile  hello.c

$ cat hello.c
#include <stdio.h>
int main(int argc, char** argv)
{
    printf("Hello container!\n");
    return 0;
}

$ cat Dockerfile
FROM scratch
WORKDIR .
ADD ./a.out /a.out
CMD ["/a.out"]

2 Steps to create the image

The a.out is generated by compiling hello.c statically so it does NOT need any user space lib to run.


$ gcc -static hello.c

$ docker build -t mini_image .
Sending build context to Docker daemon  801.3kB
Step 1/4 : FROM scratch
 --->
Step 2/4 : WORKDIR .
 ---> Using cache
 ---> 6ab802804c0d
Step 3/4 : ADD ./a.out /a.out
 ---> Using cache
 ---> 5effc7b72b0e
Step 4/4 : CMD ["/a.out"]
 ---> Using cache
 ---> 4675619c3ed7
Successfully built 4675619c3ed7
Successfully tagged mini_image:latest

3 Run it

$ docker run mini_image
Hello container!

No comments:

Post a Comment