Python社区  »  docker

Docker学习(六)image仓库

我犟不过你 • 2 月前 • 42 次点击  

类似于maven,或者github,可以将我们的镜像推送到服务器docker hub中,供别人使用,前提是要登录到docker hub。

1、创建docker hub账号

进入 https://hub.docker.com/

hub.docker.com

按照上图注册自己的账号,并登录(sign in)

sign in

登陆成功

登陆成功

2、上传我们的镜像到docker hub

通过docker login 命令登录docker hub

[root@iZ2ze7sn66bchxncut8rgsZ opt]# 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: 18351001571
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

查看下当前images :

[root@iZ2ze7sn66bchxncut8rgsZ opt]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               latest              84c5f6e03bf0        13 days ago         104MB
nginx               latest              7e4d58f0e5f3        13 days ago         133MB
centos              7                   7e6257c9f8d8        6 weeks ago         203MB
hello-world         latest              bf756fb1ae65        8 months ago        13.3kB

上传hello-world到docker hub

[root@iZ2ze7sn66bchxncut8rgsZ opt]# docker push hello-world
The push refers to repository [docker.io/library/hello-world]
9c27e219663c: Layer already exists 
errors:
denied: requested access to the resource is denied
unauthorized: authentication required

推送失败了,名称与docker hub重复了,改个名字

[root@iZ2ze7sn66bchxncut8rgsZ opt]# docker tag hello-world wrx-hello-world
[root@iZ2ze7sn66bchxncut8rgsZ opt]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               latest              84c5f6e03bf0        13 days ago         104MB
nginx               latest              7e4d58f0e5f3        13 days ago         133MB
centos              7                   7e6257c9f8d8        6 weeks ago         203MB
hello-world         latest              bf756fb1ae65        8 months ago        13.3kB
wrx-hello-world     latest              bf756fb1ae65        8 months ago        13.3kB

上传wrx-hello-world:

[root@iZ2ze7sn66bchxncut8rgsZ opt]# docker push wrx-hello-world
The push refers to repository [docker.io/library/wrx-hello-world]
9c27e219663c: Preparing 
denied: requested access to the resource is denied

仍然失败了,需要在我们上传的镜像前加上自己的账号,修改名称:

[root@iZ2ze7sn66bchxncut8rgsZ opt]# docker tag wrx-hello-world 18351001571/wrx-hello-world

再次上传:

[root@iZ2ze7sn66bchxncut8rgsZ opt]# docker push 18351001571/wrx-hello-world
The push refers to repository [docker.io/18351001571/wrx-hello-world]
9c27e219663c: Mounted from library/hello-world 
latest: digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 size: 525

上传成功,去docker hub看一下:

docker hub

删除本地镜像,重新pull,看是否能成功

[root@iZ2ze7sn66bchxncut8rgsZ ~]# docker rmi 18351001571/wrx-hello-world:latest 
Untagged: 18351001571/wrx-hello-world:latest
Untagged: 18351001571/wrx-hello-world@sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
[root@iZ2ze7sn66bchxncut8rgsZ ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               latest              84c5f6e03bf0        2 weeks ago         104MB
nginx               latest              7e4d58f0e5f3        2 weeks ago         133MB
centos              7                   7e6257c9f8d8        6 weeks ago         203MB
[root@iZ2ze7sn66bchxncut8rgsZ ~]# docker pull 18351001571/wrx-hello-world:latest
latest: Pulling from 18351001571/wrx-hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Status: Downloaded newer image for 18351001571/wrx-hello-world:latest
[root@iZ2ze7sn66bchxncut8rgsZ ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
redis                         latest              84c5f6e03bf0        2 weeks ago         104MB
nginx                         latest              7e4d58f0e5f3        2 weeks ago         133MB
centos                        7                   7e6257c9f8d8        6 weeks ago         203MB
18351001571/wrx-hello-world   latest              bf756fb1ae65        8 months ago        13.3kB
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/74031
 
42 次点击  
分享到微博