前言:
此时小伙伴们对“centos65gcc493”可能比较关心,咱们都需要分析一些“centos65gcc493”的相关知识。那么小编同时在网上搜集了一些对于“centos65gcc493””的相关知识,希望你们能喜欢,你们快快来了解一下吧!书籍来源:《CKA/CKAD应试指南:从Docker到Kubernetes完全攻略》
一边学习一边整理老师的课程内容及实验笔记,并与大家分享,侵权即删,谢谢支持!
附上汇总贴:CKA备考实验 | 汇总_热爱编程的通信人的博客-CSDN博客
镜像的命名
一般情况下,镜像是按照如下格式命名的。
服务器IP:端口/分类/镜像名:tag
如果不指明端口,默认为80,tag默认为latest,比如192.168.26.101:5000/cka/centos:v2,再比如hub.c.163.com/library/mysql:latest。分类也可以不写,比如docker.io/nginx:latest。
在把镜像上传(push)到仓库的时候,镜像必须要按这种格式命名,因为仓库地址就是由镜像前面的IP决定的。如果只是在本机使用镜像的话,可以随意命名。
查看当前系统有多少镜像。
##########实操验证##########[root@vms100 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 605c77e624dd 16 months ago 141MBregistry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end latest eca38637b06d 3 years ago 126MB[root@vms100 ~]#对镜像重新做标签
如果想给本地已经存在的镜像起一个新的名字,可以用tag来做,语法如下。
docker tag 旧的镜像名 新的镜像名
tag之后,新的镜像名和旧的镜像名是同时存在的。
步骤1:给镜像做新标签。
##########实操验证##########[root@vms100 ~]# docker tag registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end xxxx-nginx:v11-v1[root@vms100 ~]#
这里是为registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end:1.2重新做个tag,名字为xxxx-nginx:v11-v1,镜像名为xxx-nginx,标签为v11-v1,这样命名的目的是让大家看到命名的随意性,建议tag可以设置为版本号、日期等有意义的字符。
步骤2:再次查看镜像。
##########实操验证##########[root@vms100 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 605c77e624dd 16 months ago 141MBregistry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end latest eca38637b06d 3 years ago 126MBxxxx-nginx v11-v1 eca38637b06d 3 years ago 126MB[root@vms100 ~]#
可以看到对某镜像做了标签之后,看似是两个镜像,其实对应的是同一个(这类似于Linux里硬链接的概念,一个文件两个名字而已),镜像ID都是一样的。删除其中一个镜像是不会删除存储在硬盘上的文件的,只有把image id所对应的所有名字全部删除,才会从硬盘上删除。
删除镜像
如果要删除镜像的话,需要按如下语法来删除。
语法: docker rmi 镜像名:tag
比如下面要把registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end:1.2删除。
步骤1:删除镜像。
##########实操验证##########[root@vms100 ~]# docker rmi registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-endUntagged: registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end:latestUntagged: registry.cn-hangzhou.aliyuncs.com/nginx-phpfpm/nginx-end@sha256:7e90bcf2ecd7cb8569bbde4a81b0524ebf8f5946d99f39e4d4dbc4ede6bd9ff9[root@vms100 ~]#
这里可以看到只是简单的一个untagged操作,并没有任何的deleted操作。
步骤2:查看镜像。
##########实操验证##########[root@vms100 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 605c77e624dd 16 months ago 141MBxxxx-nginx v11-v1 eca38637b06d 3 years ago 126MB[root@vms100 ~]#
只有删除最后一个名字,本地文件才会被删除。
步骤3:删除镜像。
##########实操验证##########[root@vms100 ~]# docker rmi xxxx-nginx:v11-v1Untagged: xxxx-nginx:v11-v1Deleted: sha256:eca38637b06d86ac2419b24a148e7b1d815e5b907f95b7a38349afda4adc9a7bDeleted: sha256:22a233cfde23ec1edfa794e4697abcff2acb9822c3d617f8012bd2b4a59b9cb8Deleted: sha256:40b915bdf1a5d89edce54fa07f9d78c4bb018f8d82daf4cda0e6dc715efe1f48Deleted: sha256:5461f362f117f41bf73d4ab290932c1ad0b036c90de4d92c11f23b271d8fa226Deleted: sha256:8ad45536d5e4c343ec3a99fa8f759784451656862005c26db6a0fd273727d1e6Deleted: sha256:4f71ea073b438369b87f20ad9cc8aca17efcd777a98ef6a396cebaa84355e46cDeleted: sha256:1758ea933cbf0900bc59fa45893440675d66d8848c3595f6f6ae9cdac34ecaf0Deleted: sha256:d8a33133e477d367977987129313d9072e0ec80894ed4c52c2d88186f354c29a[root@vms100 ~]#查看镜像的层结构
我们所用的镜像都是从网上下载下来的,它们在制作过程中都是一点点修改的,一步步做出来的。如果要看某镜像这些步骤,可以用docker history命令,语法如下。
docker history 镜像名
查看镜像的结构。
##########实操验证###########需要docker pull hub.c.163.com/library/centos后再来查看,之前没有拉取该镜像[root@vms100 ~]# docker history hub.c.163.com/library/centosIMAGE CREATED CREATED BY SIZE COMMENT328edcd84f1b 5 years ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 5 years ago /bin/sh -c #(nop) LABEL name=CentOS Base Im… 0B <missing> 5 years ago /bin/sh -c #(nop) ADD file:63492ba809361c51e… 193MB [root@vms100 ~]#
最上层的CMD定义为,使用这个镜像生成的容器里运行的进程为/bin/bash。
导出镜像
有一些服务器无法连接到互联网,所以无法从互联网上下载镜像。在还没有私有仓库的情况下,如何把现有的镜像传输到其他机器上呢?这里我们就需要把本地已经pull下来的镜像导出为一个本地文件,这样就可以很容易地传输到其他机器。导出镜像的语法如下。
docker save 镜像名 > file.tar
先查看当前目录里的内容:
##########实操验证##########[root@vms100 ~]# lsanaconda-ks.cfg initial-setup-ks.cfg[root@vms100 ~]#
步骤1:把docker.io/nginx:latest导出为nginx.tar。
##########实操验证###########需要docker pull docker.io/nginx后再来做实验[root@vms100 ~]# docker save docker.io/nginx > nginx.tar[root@vms100 ~]# lsanaconda-ks.cfg initial-setup-ks.cfg nginx.tar[root@vms100 ~]#
如果导出多个镜像的话,语法如下。
docker save 镜像名1 镜像名2 镜像名3 ... > file.tar
不可以使用如下方式。
docker save 镜像名1 > file.tar docker save 镜像名2 >> file.tar...
步骤2:导出所有的镜像。
##########实操验证###########需要拉去hub.c.163.com/library/wordpress和hub.c.163.com/library/mysql镜像后验证[root@vms100 ~]# docker save docker.io/nginx hub.c.163.com/library/wordpress hub.c.163.com/library/centos hub.c.163.com/library/mysql > all.tar[root@vms100 ~]# lsall.tar anaconda-ks.cfg initial-setup-ks.cfg nginx.tar[root@vms100 ~]#
步骤3:删除所有的镜像,有以下3种方法。
(1)关闭docker,清空/var/ib/docker/,记住是清空/var/lib/docker/里的内容,不是删除此目录。
(2)手动一个一个地删除。
(3)写脚本,内容如下。
##########实操验证##########[root@vms100 ~]# cat rm_all_image.sh #!/bin/bashfile=$(mktemp)docker images | grep -v REPOSITORY | awk '{print $1":"$2}' >> $file while read line ; do docker rmi $line done < $file[root@vms100 ~]# [root@vms100 ~]# chmod +x rm_all_image.sh [root@vms100 ~]# ./rm_all_image.sh Untagged: nginx:latestUntagged: nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31Deleted: sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85Deleted: sha256:b625d8e29573fa369e799ca7c5df8b7a902126d2b7cbeb390af59e4b9e1210c5Deleted: sha256:7850d382fb05e393e211067c5ca0aada2111fcbe550a90fed04d1c634bd31a14Deleted: sha256:02b80ac2055edd757a996c3d554e6a8906fd3521e14d1227440afd5163a5f1c4Deleted: sha256:b92aa5824592ecb46e6d169f8e694a99150ccef01a2aabea7b9c02356cdabe7cDeleted: sha256:780238f18c540007376dd5e904f583896a69fe620876cabc06977a3af4ba4fb5Deleted: sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851fUntagged: hub.c.163.com/library/wordpress:latestUntagged: hub.c.163.com/library/wordpress@sha256:fa3f8358cca5c4c5a37afca935f586b136353e2de14340788482db3ab0e97dcaDeleted: sha256:dccaeccfba3693896ee17c63257e0159b0c909ac33cc7c846f5598de0d7d19fbDeleted: sha256:9d9dde03d43e6d7da3832f33c8ab4290157c32038cf02f9b730d982066cee18cDeleted: sha256:e712cda6350b06680df20dc3f67cbb3460299467a687dfd47a4554949d08715bDeleted: sha256:665a8cb6d5629102618ac9614511582e03d1623c8fe5fc405037f8bfb72c57b0Deleted: sha256:7bbc310cf90d2c1b3b0240066af1bd30ff44fa5e0e4109b19c14670441e06b31Deleted: sha256:f6df728ba54f30e0d216ba3a5810551301833a0583bfe7f0563f59614c25e54bDeleted: sha256:70ab02f5fd3c72a2f8ba5b0bc56c43313f0b59f8281f3adfd5a44661d0dcdd8dDeleted: sha256:217150f969f9f1350f400c2052e9837d08716235dc49e295b1cb213e113c50d2Deleted: sha256:37b99f5af2f52ea8df303bf7283567f2d0b3ed087f0498b17538b1c89bcc618aDeleted: sha256:7b456ed31909e1210207f16ea9c6a562ec0ecda80c6c437da47c50dadb5131deDeleted: sha256:81f25a928d4b1fc8e8b52228acf1a7a47c95385688b608193f72ef673f067b26Deleted: sha256:9305a767577b64e9520395c5952a8ccf6767d1eb3b9d60e15726cdad9adbe4b2Deleted: sha256:203f95a609cf0c3a13547ae367c64054a0c97737d67d82c8e164c409713912efDeleted: sha256:7cbb3ea89c414fc8be3470459efd85ec972545c460ad6c2c7fcfaa2a13e50fbbDeleted: sha256:d9dcc699f04b520bb533e83e7460ff4da2dcf12dfcc6be7cba8ac13f9e3c1c12Deleted: sha256:ffad61618a7db0f43237fb3e90c6f76708fe9a3897c594dce1df88a4353edfccDeleted: sha256:b36ec8b16c5ea658e42c7a7bc305d8c0c3101efb85160c91a8e2b2bc3fdb6113Deleted: sha256:72fdb054d2ddd673cd4606acf88d7512e4f86b552fc9ac493e7f3395ab610a9bDeleted: sha256:2c40c66f7667aefbb18f7070cf52fae7abbe9b66e49b4e1fd740544e7ceaebdcUntagged: hub.c.163.com/library/centos:latestUntagged: hub.c.163.com/library/centos@sha256:ab7e9c357fa8e5c822dd22615d3f704090780df1e089ac4ff8c6098f26a71fefDeleted: sha256:328edcd84f1bbf868bc88e4ae37afe421ef19be71890f59b4b2d8ba48414b84dDeleted: sha256:b362758f4793674edb79ec5c7192074b2eacf200c006e127069856484526ccf2Untagged: hub.c.163.com/library/mysql:latestUntagged: hub.c.163.com/library/mysql@sha256:b2bce1a792237ac5df78877d583f34b09ab023a77130921a6bcce67ce2d24ff0Deleted: sha256:9e64176cd8a206f88336506fe52cd8f87423147dc197d0250175dddc39465e90Deleted: sha256:2d79a736de4c447bbad1801e9e4568d6b5f2ba4cc2d5e31a908af9bf51e9b3b3Deleted: sha256:6e4bd70bb55bcb5ad9850d51c13fd6d40c66aae50bca7741fd940561b2a148e2Deleted: sha256:75c1f169d72e1475a4427f528343669d2973701589a26791aacfda1dd5df4f66Deleted: sha256:b934b913f0c1280d85ee196c29a5b246087d74a2a6747b479b4a677f05d11626Deleted: sha256:47be8aca05b42f1e1a4c9e7058f1eaf59a68119f7e7cbec56b9a68aeb8ed8fc5Deleted: sha256:ba5061936a764f53b2d1118db1f491f06f4afb0a1a19f94aa0d07ee3ac1a5949Deleted: sha256:0bfdd0113d6e2adeef68baa97ab6da9900698f656e9ca193b274cb25e67a12acDeleted: sha256:edcf46029534ffee6cbf4b621473ad513b66b60ab0e9f8c15107b841c2986755Deleted: sha256:bd0eace476f07ae4c41014e81823062d43f3c848aa5337061f59833590ff15f9Deleted: sha256:4a0ae64be2238aa31b864ee1e396b24f672025bcf98656a10e4ee3158b2c8399Deleted: sha256:295d6a056bfd381abf9c462629066b0458373045a1dca7d13ef6128cb38c977e[root@vms100 ~]#
步骤4:查看现有镜像。
##########实操验证##########[root@vms100 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE[root@vms100 ~]#导入镜像
既然上面已经把镜像导出为一个文件了,那么我们就需要把这个文件导入,语法如下。
docker load -i file.tar
步骤1:把nginx.tar导入为镜像。
##########实操验证##########[root@vms100 ~]# docker load -i nginx.tar 2edcec3590a4: Loading layer [==================================================>] 83.86MB/83.86MBe379e8aedd4d: Loading layer [==================================================>] 62MB/62MBb8d6e692a25e: Loading layer [==================================================>] 3.072kB/3.072kBf1db227348d0: Loading layer [==================================================>] 4.096kB/4.096kB32ce5f6a5106: Loading layer [==================================================>] 3.584kB/3.584kBd874fd2bc83b: Loading layer [==================================================>] 7.168kB/7.168kBLoaded image: nginx:latest[root@vms100 ~]#
步骤2:导入所有镜像。
##########实操验证##########[root@vms100 ~]# docker load -i all.tar Loaded image: nginx:latest2c40c66f7667: Loading layer [==================================================>] 129.3MB/129.3MBddd6dcab19ff: Loading layer [==================================================>] 204.7MB/204.7MBf0c367fa8636: Loading layer [==================================================>] 3.584kB/3.584kB0fd7a67d49b3: Loading layer [==================================================>] 7.699MB/7.699MB53da01089a82: Loading layer [==================================================>] 10.24kB/10.24kB3d2582fdede2: Loading layer [==================================================>] 9.728kB/9.728kB315db89f9acb: Loading layer [==================================================>] 4.096kB/4.096kB2da371244fc1: Loading layer [==================================================>] 7.68kB/7.68kB354b4ef9664b: Loading layer [==================================================>] 13.01MB/13.01MBadfd7c98cdf6: Loading layer [==================================================>] 4.096kB/4.096kB8747705a74d9: Loading layer [==================================================>] 33.01MB/33.01MB5a151fa4136e: Loading layer [==================================================>] 11.78kB/11.78kBc8c6d352c96e: Loading layer [==================================================>] 4.608kB/4.608kBfed26d7fe7b9: Loading layer [==================================================>] 6.04MB/6.04MB4214911d5945: Loading layer [==================================================>] 4.608kB/4.608kB6671cb9eb6b3: Loading layer [==================================================>] 7.168kB/7.168kB562dd11ed871: Loading layer [==================================================>] 25.12MB/25.12MB53e16fa1f104: Loading layer [==================================================>] 10.24kB/10.24kBLoaded image: hub.c.163.com/library/wordpress:latestb362758f4793: Loading layer [==================================================>] 200.1MB/200.1MBLoaded image: hub.c.163.com/library/centos:latest295d6a056bfd: Loading layer [==================================================>] 129.2MB/129.2MB3b7c5f5acc82: Loading layer [==================================================>] 344.6kB/344.6kBda4155a7d640: Loading layer [==================================================>] 4.657MB/4.657MBdaf31ec3573d: Loading layer [==================================================>] 1.536kB/1.536kB904af8e2b2d5: Loading layer [==================================================>] 39.68MB/39.68MB2bee3420217b: Loading layer [==================================================>] 25.09kB/25.09kBe5de8ba20fae: Loading layer [==================================================>] 3.584kB/3.584kB9e615ff77b4f: Loading layer [==================================================>] 240.5MB/240.5MBfa9efdcb088a: Loading layer [==================================================>] 6.144kB/6.144kB3c376267ac82: Loading layer [==================================================>] 9.216kB/9.216kB8129a85b4056: Loading layer [==================================================>] 1.536kB/1.536kBLoaded image: hub.c.163.com/library/mysql:latest[root@vms100 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 605c77e624dd 16 months ago 141MBhub.c.163.com/library/wordpress latest dccaeccfba36 5 years ago 406MBhub.c.163.com/library/centos latest 328edcd84f1b 5 years ago 193MBhub.c.163.com/library/mysql latest 9e64176cd8a2 6 years ago 407MB[root@vms100 ~]#
标签: #centos65gcc493