- 手动制作容器镜像


    1.启动容器
[root@centos201 ~]# docker run --name base -d centos:7 tail -f /etc/hosts

    2.安装服务
[root@centos201 ~]# docker exec -it base bash
....
[root@40235cf19d2e /]# curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# yum -y install nginx
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# rm -rf /usr/share/nginx/html/* 
[root@40235cf19d2e /]# 
[root@40235cf19d2e /]# echo www.oldboyedu.com > /usr/share/nginx/html/index.html
[root@40235cf19d2e /]# 
[root@40235cf19d2e /]# nginx -g 'daemon off;'  # 在前台启动nginx服务
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# exit 
exit
[root@centos201 ~]# 

    3.将容器提交为镜像
[root@centos201 ~]# docker container commit -a linux86@oldboyedu.com -m 'shou dong v0.1' base oldboyedu-centos-nginx:v0.1  # -a表示声明作者信息,-m表示声明注释信息。
sha256:1b12c02f3eee2cd802232af1a1b0e8d14ae92017bf442a5fefdcbae0053f7bf7
[root@centos201 ~]# 


    4.查看镜像的详细信息
[root@centos201 ~]# docker inspect oldboyedu-centos-nginx:v0.1 


    5.手动再次提交测试
[root@centos201 ~]# docker run -d  --name myweb01 oldboyedu-centos-nginx:v0.1
421c63c8f77456096438fd7e5c06597b1fc16819db5238c52516369ba3c787b1
[root@centos201 ~]# 
[root@centos201 ~]# docker ps
CONTAINER ID   IMAGE                         COMMAND                CREATED         STATUS        PORTS     NAMES
421c63c8f774   oldboyedu-centos-nginx:v0.1   "tail -f /etc/hosts"   2 seconds ago   Up 1 second             myweb01
[root@centos201 ~]# 
[root@centos201 ~]# 
[root@centos201 ~]# 
[root@centos201 ~]# docker run -d  --name myweb02 oldboyedu-centos-nginx:v0.1  nginx -g 'daemon off;'
ed611aafcd65a5249993ab00f84d8b27a14830e6e248d525e5ee4be9eff146b1
[root@centos201 ~]# 
[root@centos201 ~]# docker ps
CONTAINER ID   IMAGE                         COMMAND                  CREATED          STATUS          PORTS     NAMES
ed611aafcd65   oldboyedu-centos-nginx:v0.1   "nginx -g 'daemon of…"   2 seconds ago    Up 1 second               myweb02
421c63c8f774   oldboyedu-centos-nginx:v0.1   "tail -f /etc/hosts"     16 seconds ago   Up 15 seconds             myweb01
[root@centos201 ~]# 
[root@centos201 ~]# 
[root@centos201 ~]# docker container commit myweb02 oldboyedu-centos-nginx:v0.2
sha256:4cee54a629e82d40b17f4bcf380dce00499baa38caabfdb8b7d2290b4daa0cbc
[root@centos201 ~]# 
[root@centos201 ~]# docker run -d  --name myweb03 oldboyedu-centos-nginx:v0.2
1fda0fd540088f8d5af23c898f45083877f3fd0be44ce8f8cf174945d13b40de
[root@centos201 ~]# 
[root@centos201 ~]# 
[root@centos201 ~]# docker ps
CONTAINER ID   IMAGE                         COMMAND                  CREATED              STATUS              PORTS     NAMES
1fda0fd54008   oldboyedu-centos-nginx:v0.2   "nginx -g 'daemon of…"   7 seconds ago        Up 7 seconds                  myweb03
ed611aafcd65   oldboyedu-centos-nginx:v0.1   "nginx -g 'daemon of…"   53 seconds ago       Up 53 seconds                 myweb02
421c63c8f774   oldboyedu-centos-nginx:v0.1   "tail -f /etc/hosts"     About a minute ago   Up About a minute             myweb01
[root@centos201 ~]# 
[root@centos201 ~]# docker container inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" `docker container ps -lq`
172.17.0.4
[root@centos201 ~]# 
[root@centos201 ~]# curl 172.17.0.4
www.oldboyedu.com
[root@centos201 ~]# 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值