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

4次阅读

共计 569 个字符,预计需要花费 2 分钟才能阅读完成。

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
正文完
 0