关于docker:32-Diy一个Base-Image

1. Hello World Image 应用示例

# 查看镜像列表
docker image ls
docker images

# 装置镜像
docker pull hello-world

# 启动镜像
docker run hello-world

# 删除镜像
docker image remove $image_id
docker 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

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理