1. Hello World Image 应用示例

# 查看镜像列表docker image lsdocker images# 装置镜像docker pull hello-world# 启动镜像docker run hello-world# 删除镜像docker image remove $image_iddocker rmi $image_id
docker run -it选项的益处就是能够在与容器互动完结之后,可能应用ctrl c顺利地退出交互

2. 编写hello docker

编写c程序

#include <stdio.h>int main(){   printf("hello docker\n");}

编译c程序

gcc hello.c -o hello

编辑Dockerfile

# FROM scratch示意不依赖任何镜像FROM scratch# 增加文件到/目录ADD hello /# 执行命令CMD ["/hello"]

从.目录查找Dockerfile,生成镜像

docker image build -t siguoya/hello-world .#或docker build -t siguoya/hello-world .

基于镜像,主动创立一个容器并运行Dockerfile中的CMD

docker run siguoya/hello-world

查看镜像的构建历史

docker history siguoya/hello-world