博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
docker入门(二)
阅读量:2383 次
发布时间:2019-05-10

本文共 5050 字,大约阅读时间需要 16 分钟。

打造自己的镜像

首先我们启动busybox镜像为容器,在该容器中安装一个小工具,再将这个容器保存为新的镜像

首先我们下载一个镜像,再启动容器

[root@centos ~]# docker pull learn/tutorialUsing default tag: latestTrying to pull repository docker.io/learn/tutorial ... latest: Pulling from docker.io/learn/tutorial271134aeb542: Pull complete Digest: sha256:2933b82e7c2a72ad8ea89d58af5d1472e35dacd5b7233577483f58ff8f9338bdStatus: Downloaded newer image for docker.io/learn/tutorial:latest[root@centos ~]# docker run -d -it --name=tutorial docker.io/learn/tutorial /bin/bash87370a9b56b0810257f8172b82b1e219c15b2a0999ad6703d4da28fc1e5d992f[root@centos ~]# docker psCONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS               NAMES87370a9b56b0        docker.io/learn/tutorial   "/bin/bash"         2 minutes ago       Up 2 minutes                            tutorial

进入这个容器

[root@centos ~]# docker exec -it tutorial bashroot@87370a9b56b0:/#

默认tutorial是不带ping工具的,我们下载一个ping

root@87370a9b56b0:/# ping www.baidu.combash: ping: command not foundroot@87370a9b56b0:/# apt-get install -y pingReading package lists... DoneBuilding dependency tree... DoneNote, selecting 'iputils-ping' instead of 'ping'The following NEW packages will be installed:  iputils-ping0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.Need to get 56.1 kB of archives.After this operation, 143 kB of additional disk space will be used.Get:1 http://archive.ubuntu.com/ubuntu/ precise/main iputils-ping amd64 3:20101006-1ubuntu1 [56.1 kB]Fetched 56.1 kB in 15s (3580 B/s)                                                                                                                                                      debconf: delaying package configuration, since apt-utils is not installedSelecting previously unselected package iputils-ping.(Reading database ... 7545 files and directories currently installed.)Unpacking iputils-ping (from .../iputils-ping_3%3a20101006-1ubuntu1_amd64.deb) ...Setting up iputils-ping (3:20101006-1ubuntu1) ...root@87370a9b56b0:/# ping www.baidu.comPING www.a.shifen.com (115.239.211.112) 56(84) bytes of data.64 bytes from 115.239.211.112: icmp_req=1 ttl=47 time=35.8 ms64 bytes from 115.239.211.112: icmp_req=2 ttl=47 time=35.8 ms^C--- www.a.shifen.com ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1001msrtt min/avg/max/mdev = 35.816/35.822/35.828/0.006 ms

保存修改后的容器为新镜像

先退出容器

root@87370a9b56b0:/# exit                         exit[root@centos ~]# docker psCONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS               NAMES87370a9b56b0        docker.io/learn/tutorial   "/bin/bash"         About an hour ago   Up About an hour                        tutorial

保存修改后容器为镜像

[root@centos ~]# docker commit 87370a9b56b0 registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage:1.0.0sha256:209e769fa98794f7e265fde0dcb78af78dda3abf01ffb0bb1e3dd7d3e248a4d6[root@centos ~]# docker imagesREPOSITORY                                             TAG                 IMAGE ID            CREATED              SIZEregistry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage      1.0.0               209e769fa987        3 seconds ago        152.8 MBregistry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox   1.0.0               14889344ccaa        About a minute ago   152.8 MBdocker.io/busybox                                      latest              e02e811dd08f        5 weeks ago          1.093 MBdocker.io/learn/tutorial                               latest              a7876479f1aa        3 years ago          128 MB

新的newimage镜像被保存出来了,我们验证newimage是否包含刚装的ping,先删除已经启动的容器,在启动newimage。

[root@centos ~]# docker stop 87370a9b56b087370a9b56b0[root@centos ~]# docker rm 87370a9b56b087370a9b56b0[root@centos ~]# docker run -d -it --name=newimage registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage:1.0.0 /bin/bash f156289920964f3e9ce3878f7a7d2714361173ebe1105c423e988dfe2ec97264[root@centos ~]# docker ps CONTAINER ID        IMAGE                                                     COMMAND             CREATED             STATUS              PORTS               NAMESf15628992096        registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage:1.0.0   "/bin/bash"         3 seconds ago       Up 3 seconds                            newimage

进入容器验证下

[root@centos ~]# docker exec -it newimage bashroot@f15628992096:/# ping www.baidu.comPING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.64 bytes from 115.239.210.27: icmp_req=1 ttl=47 time=47.3 ms64 bytes from 115.239.210.27: icmp_req=2 ttl=47 time=47.0 ms^C--- www.a.shifen.com ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1001msrtt min/avg/max/mdev = 47.019/47.188/47.358/0.275 ms

我们再把newimage推送到阿里云仓库

[root@centos ~]# docker push registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage:1.0.0The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/wzgdxg/newimage]91466e7b50f0: Pushed ee1ba0cc9b81: Pushed 1.0.0: digest: sha256:cdcd535beb974a7304c39f19b11bf21f6211441eea65ca445f170b07700bc0ec size: 718

转载地址:http://smbab.baihongyu.com/

你可能感兴趣的文章
C++调用IDL程序的做法(一)
查看>>
外部修改应用程序图标的做法
查看>>
database disk image is malformed解决方法
查看>>
有关error PRJ0003错误的思考
查看>>
实现自定义对话框程序快捷键的两种方法
查看>>
如何对抗微软霸权,google给我们上了一课
查看>>
未能将基于用户的Visual C++项目设置保存到user文件错误的解决
查看>>
获取windows版本信息的做法
查看>>
忆父亲
查看>>
png库结合zlib库使用出现的一个链接问题的解决
查看>>
STL数组和com数组相互转换的做法
查看>>
开发平台软件中关于第三方库管理的一些思考
查看>>
svn创建分支的做法
查看>>
“当前不会命中断点。源代码与原始版本不同”的问题的有效解决办法
查看>>
对面向对象和面向过程的一些新理解
查看>>
软件开发中的资源管理
查看>>
有关博客的一些断想
查看>>
Windows Server2008上安装VS2008出错及解决办法
查看>>
打开word2010每次都要配置进度的解决办法
查看>>
略论并行处理系统的日志设计
查看>>