1、编写一个二进制的文件: hello.c
#include<stdio.h>
int main()
{
printf("hello world\n");
}
2、检查环境中是否已安装了 gcc和glibc-static(用于编译C语言程序)
history | grep yum
没有的话,则安装
yum install gcc
yum install glibc-static
3、编译hello.c文件
gcc -static hello.c -o hello
4、检查当前目录的文件
[root@localhost hello-world]# ls
hello hello.c
5、创建Dockerfile文件
FROM scratch
ADD hello /
CMD ["/hello"]
注:FROM scratch #制作base image
FROM centos #使用base image(centos)
6、构建image
docker build -t busedon/hello-world .
7、查询image
[root@localhost hello-world]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busedon/hello-world latest e2086ed7d9f3 17 seconds ago 861kB