Centos7 Docker 创建 hello 镜像

本文详细记录了在CentOS7环境中,利用Docker CE社区版创建名为hello的Docker镜像的全过程。从环境搭建,包括gcc及必要库的安装,到C语言程序的编写与编译,再到Dockerfile的编写与镜像的构建,直至镜像的运行与验证。

在centos7环境下使用docker-ce社区版,创建hello镜像的记录

参考链接:

根据Dockerfile创建hello docker镜像

如何创建一个 Docker 镜像

Docker image创建之Hello world

代码操作

yum install -y gcc glibc glibc-static #安装c环境
pwd
/root/winsonzhao/hello-zyl
vim hello.c #编辑c文档
    #include<stdio.h>
    int main()
    {
      printf("winsonzhao! hello docker!\n");
    }
gcc -static hello.c -o hello #编译
vim Dockerfile #创建镜像
    FROM scratch #从头创建docker镜像,不依赖任何base镜像
    ADD hello / #将本地的hello文件添加到镜像的根目录下/
    CMD ["/hello"] #执行根目录下的hello文件
ls   #创建docker前的所有的文件
Dockerfile  hello  hello.c
docker build -t winsonzhao/hello-zyl . #创建docker,-t后面接tag名称,.表示在当前目录下找dockerfile
    Sending build context to Docker daemon  864.8kB
    Step 1/3 : FROM scratch
     ---> 
    Step 2/3 : ADD hello /
     ---> ad11d3bf3d66
    Step 3/3 : CMD ["/hello"]
     ---> Running in 1a4a631dac1a
    Removing intermediate container 1a4a631dac1a
     ---> ea366488e1a8
    Successfully built ea366488e1a8
    Successfully tagged winsonzhao/hello-zyl:latest
docker images #镜像
REPOSITORY				TAG                 IMAGE ID            CREATED             SIZE
winsonzhao/hello-zyl 	latest              ea366488e1a8        11 seconds ago      861kB
docker run winsonzhao/hello-zyl #运行
winsonzhao! hello docker!

安装gcc

当前目录

编辑hello.c

编译hello

编辑Dockerfile

当前目录下的文件

Docker创建hello镜像

镜像列表

运行镜像

导出镜像

压缩包的结构

到此结束,d=====( ̄▽ ̄*)b

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值