CentOS 上的docker 镜像管理

docker 的镜像结构

图片[1]-CentOS 上的docker 镜像管理-我的运维技术站
  • docker镜像是一个典型的分层结构
  • 只有最上面一层是可写的 其他都是只读的固化到镜像的
  • 每次推送都是增量的
图片[2]-CentOS 上的docker 镜像管理-我的运维技术站

镜像名称的结构

${registry_ name}/${repository. name}/${image. name}:${tag. name}

例如:

docker.io/library/alpine:3.10.1

登陆到dokcer.io

[root@VM-4-10-centos ~]# docker login docker.io
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: 92fuge
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

查看已经登陆的信息

[root@VM-4-10-centos ~]# cat /root/.docker/config.json 
{
	"auths": {
		"https://index.docker.io/v1/": {
			"auth": "5qyi6L+O5p2l5Yiw5a+M5ZOl6L+Q57u0"
		}
	}
echo "5qyi6L+O5p2l5Yiw5a+M5ZOl6L+Q57u0" |base64 -d

搜索镜像

图片[3]-CentOS 上的docker 镜像管理-我的运维技术站

拉取镜像

  • 如果不指定tag 默认下载最新版本 latest
[root@VM-4-10-centos]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
801bfaa63ef2: Pull complete 
Digest: sha256:3c7497bf0c7af93428242d6176e8f7905f2201d8fc5861f45be7a346b5f23436
Status: Downloaded newer image for alpine:latest
[root@alice ~]# 

也可以指定版本下载

[root@VM-4-10-centos]# docker pull alpine:3.10.3
3.10.3: Pulling from library/alpine
89d9c30c1d48: Pull complete 
Digest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a
Status: Downloaded newer image for alpine:3.10.3
[root@VM-4-10-centos]# docker pull docker.io/library/alpine:3.10.3
3.10.3: Pulling from library/alpine
Digest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a
Status: Image is up to date for alpine:3.10.3
[root@VM-4-10-centos]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              389fef711851        3 weeks ago         5.58MB
alpine              3.10.3              965ea09ff2eb        14 months ago       5.55MB
[root@VM-4-10-centos]# 
如果使用官方的docker.io 可以不写前面的docker.io/library/ 因为默认就是公开的  如果是自己的或者其他仓库 需要写全

给镜像打tag(标签)

[root@VM-4-10-centos]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              389fef711851        3 weeks ago         5.58MB
alpine              3.10.3              965ea09ff2eb        14 months ago       5.55MB
[root@VM-4-10-centos]# docker tag 965ea09ff2eb docker.io/mmdghh/alpine:v3.10.3
[root@VM-4-10-centos]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              389fef711851        3 weeks ago         5.58MB
alpine              3.10.3              965ea09ff2eb        14 months ago       5.55MB
mmdghh/alpine       v3.10.3             965ea09ff2eb        14 months ago       5.55MB
[root@VM-4-10-centos]# 
IMAGE ID一样的话说明镜像是一样的 前面的tag只是一个指针 就像软链接

推送到远程仓库(在这里还是建议自己的镜像或者代码仓库放到国内—俄乌冲突西方禁止了俄罗斯很多的网站希望国家在源码仓库这块大力发展)

[root@VM-4-10-centos ~]# docker push registry.cn-beijing.aliyuncs.com/92fuge/alpine:3.10.3
The push refers to repository [registry.cn-beijing.aliyuncs.com/92fuge/alpine]
77cae8ab23bf: Pushed 
3.10.3: digest: sha256:e4355b66995c96b4b468159fc5c7e3540fcef961189ca13fee877798649f531a size: 528

推送后可以在网页看到对应的镜像

图片[4]-CentOS 上的docker 镜像管理-我的运维技术站

推送一个latest版本

[root@VM-4-10-centos ~]# docker tag alpine:3.10.3 registry.cn-beijing.aliyuncs.com/92fuge/alpine:latest
[root@VM-4-10-centos ~]# docker push registry.cn-beijing.aliyuncs.com/92fuge/alpine:latest
The push refers to repository [registry.cn-beijing.aliyuncs.com/92fuge/alpine]
77cae8ab23bf: Layer already exists 
latest: digest: sha256:e4355b66995c96b4b468159fc5c7e3540fcef961189ca13fee877798649f531a size: 528
[root@VM-4-10-centos ~]# 
图片[5]-CentOS 上的docker 镜像管理-我的运维技术站

删除镜像

[root@VM-4-10-centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              389fef711851        3 weeks ago         5.58MB
alpine              3.10.3              965ea09ff2eb        14 months ago       5.55MB
registry.cn-beijing.aliyuncs.com/92fuge/alpine       latest              965ea09ff2eb        14 months ago       5.55MB
registry.cn-beijing.aliyuncs.com/92fuge/alpine       v3.10.3             965ea09ff2eb        14 months ago       5.55MB
[root@VM-4-10-centos ~]# docker rmi 965ea09ff2eb
Error response from daemon: conflict: unable to delete 965ea09ff2eb (must be forced) - image is referenced in multiple repositories #这个ID有多个tag 所以需要用-f 来删除
[root@alice ~]# docker rmi -f 965ea09ff2eb 
Untagged: alpine:3.10.3
Untagged: alpine@sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a 先去掉tag再删除
Untagged: registry.cn-beijing.aliyuncs.com/92fuge/alpine:latest
Untagged: registry.cn-beijing.aliyuncs.com/92fuge/alpine:v3.10.3
Untagged: registry.cn-beijing.aliyuncs.com/92fuge/alpine@sha256:e4355b66995c96b4b468159fc5c7e3540fcef961189ca13fee877798649f531a
Deleted: sha256:965ea09ff2ebd2b9eeec88cd822ce156f6674c7e99be082c7efac3c62f3ff652
Deleted: sha256:77cae8ab23bf486355d1b3191259705374f4a11d483b24964d2f729dd8c076a0
[root@VM-4-10-centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              389fef711851        3 weeks ago         5.58MB
 

 

------本页内容已结束,喜欢请分享------

感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
喜欢就支持一下吧
点赞3765赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称 夸夸
夸夸
还有吗!没看够!
表情代码图片

    暂无评论内容