前言
目前的状况下,国内很多的镜像服务网站停服。而且网络或者其他的原因,经常导致拉取镜像时失败,令人非常的懊恼。我能想到的解决办法:① 可以做一个相对完整的镜像,保存供不时之需。 ②平时下载好的镜像保存起来,用时直接load ③使用阿里云构建自己的镜像库。
今天要说的是第二种。假设我们要保存下载好的memcache镜像。步骤记录如下
一、保存镜像到本地
[root@centos-node2 ~]# docker images #显示所有镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 2 years ago 141MB
memcached latest 752e592c22f1 2 years ago 89.1MB
[root@centos-node2 ~]# docker save -o memcached_latest.tar memcached:latest
[root@centos-node2 ~]#
[root@centos-node2 ~]# docker stop my-memcache #关闭容器
my-memcache
[root@centos-node2 ~]#
[root@centos-node2 ~]#
[root@centos-node2 ~]# docker rmi -f 752e #删除镜像
Deleted: sha256:752e592c22f149eca4df622f334aadad06763c93d3f207e5d1d320efdf6ff861
[root@centos-node2 ~]# docker images #删除后显示一下
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 2 years ago 141MB
[root@centos-node2 ~]#
二、使用本地保存的镜像
[root@centos-node2 ~]#
[root@centos-node2 ~]#
[root@centos-node2 ~]# ls
anaconda-ks.cfg memcached_latest.tar original-ks.cfg
[root@centos-node2 ~]# docker load -i memcached_latest.tar
Loaded image: memcached:latest
[root@centos-node2 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 2 years ago 141MB
memcached latest 752e592c22f1 2 years ago 89.1MB
[root@centos-node2 ~]#
总结
镜像文件保存到本地,可以解决我们拉取不到镜像的问题。但是也有缺点,镜像所占空间较大的话,就是不太好保存。建议放到网盘上好了。