Scratch是一个空的Docker镜像。
编写C程序 hello.c:
- #include
- int main()
- {
- printf("hello docker\n");
- }
编译成一个二进制文件:
- $ gcc --static -o hello hello.c
- $ ./hello
- hello docker
- $
编写Dockerfile:
- FROM scratch
- ADD hello /
- CMD ["/hello"]
构建:
- $ docker build -t hello .
- $ docker image ls
- REPOSITORY TAG IMAGE ID CREATED SIZE
- hello latest 2936e77a9daa 40 minutes ago 872kB
运行:
- $ docker container run -it hello
- hello docker
原始的centos没有vim和ifconfig:
- [root@localhost dockerfile]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- hello-world latest feb5d9fea6a5 3 weeks ago 13.3kB
- centos latest 5d0da3dc9764 4 weeks ago 231MB
- elasticsearch 7.14.2 2abd5