容器学习 之 本地镜像与共有镜像(十)

共有镜像docker hub

  1. 首先得在 Docker Hub 上注册一个账号。
  2. 在 Docker Host 上登录。
root@ubuntu:/home/yj# docker login
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: laster0xox0
Password: 
Login Succeeded
  1. 修改镜像的 repository 使之与 Docker Hub 账号匹配。
    Docker Hub 为了区分不同用户的同名镜像,镜像的 registry 中要包含用户名,完整格式为:[username]/image:tag
root@ubuntu:/home/yj# docker tag httpd laster0xox0/httpd:v1
root@ubuntu:/home/yj# docker images laster0xox0/httpd
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
laster0xox0/httpd   v1                  0240c8f5816c        10 days ago         132MB
  1. 通过 docker push 将镜像上传到 Docker Hub。 Docker 会上传镜像的每一层。
root@ubuntu:/home/yj# docker push laster0xox0/httpd:v1
The push refers to repository [docker.io/laster0xox0/httpd]
7857c7afb135: Mounted from library/httpd 
0ace1cc25781: Mounted from library/httpd 
355bd981febe: Mounted from library/httpd 
504b6a6a6fd2: Mounted from library/httpd 
237472299760: Mounted from library/httpd 
v1: digest: sha256:a1ae45c9153b02ccf2d790882a7aa833fcef8cc1fa5fd3cc3990c2e41fb47c6c size: 1367
  1. 登录 https://hub.docker.com,在Public Repository 中就可以看到上传的镜像。如果要删除上传的镜像,只能在 Docker Hub 界面上操作。

  2. 这个镜像可被其他 Docker host 下载使用了。

root@ubuntu:/home/yj# docker pull laster0xox0/httpd:v1
v1: Pulling from laster0xox0/httpd
Digest: sha256:a1ae45c9153b02ccf2d790882a7aa833fcef8cc1fa5fd3cc3990c2e41fb47c6c
Status: Image is up to date for laster0xox0/httpd:v1

本地仓库Registry

  1. 启动 registry 容器。
root@ubuntu:/home/yj# docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry:2
Unable to find image 'registry:2' locally
2: Pulling from library/registry
d6a5679aa3cf: Pull complete 
ad0eac849f8f: Pull complete 
2261ba058a15: Pull complete 
f296fda86f10: Pull complete 
bcd4a541795b: Pull complete 
Digest: sha256:5a156ff125e5a12ac7fdec2b90b7e2ae5120fa249cf62248337b6d04abc574c8
Status: Downloaded newer image for registry:2
0e9835e9c0cebbe31aeabc076c1df8a24a7fa2435266882da5db6ac440d27899
  1. 通过 docker tag 重命名镜像,使之与 registry 匹配。
root@ubuntu:/home/yj# docker tag laster0xox0/httpd:v1 127.0.0.1:5000/laster0xox0/httpd:v1

repository 的完整格式为:[registry-host]:[port]/[username]/xxx

  1. 通过 docker push 上传镜像。
root@ubuntu:/home/yj# docker push 127.0.0.1:5000/laster0xox0/httpd:v1
The push refers to repository [127.0.0.1:5000/laster0xox0/httpd]
7857c7afb135: Pushed 
0ace1cc25781: Pushed 
355bd981febe: Pushed 
504b6a6a6fd2: Pushed 
237472299760: Pushed 
  1. 查看本地镜像
root@ubuntu:/myregistry/docker/registry/v2/repositories# docker search 127.0.0.1:5000/laster0xox0
Error response from daemon: Unexpected status code 404
root@ubuntu:/myregistry/docker/registry/v2/repositories# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":["laster0xox0/httpd"]}
  1. 现在已经可通过 docker pull 从本地 registry 下载镜像了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值