3.2 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_iddocker 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
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论