环境ubuntu 18.04
安装docker
sudo apt update
sudo apt install docker.io
centos
yum install docker.io
接下来写一个hello程序 并编译成二进制
#include<stdio.h>
int main()
{
printf("hello\n");
}
$gcc hello.c -o hello
编辑Dockerfile
FROM scratch #从哪个镜像引入
ADD hello / #将文件添加进根目录
CMD ["/hello"] #程序
生成image 查看并运行
docker build -t hpb/hello .
查看
[root@hpb hello]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
hello latest 85f4d25d3523 35 minutes ago 8.44 kB
run
docker run hello
hello
run