共有镜像docker hub
- 首先得在 Docker Hub 上注册一个账号。
- 在 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
- 修改镜像的 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
- 通过 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
-
登录 https://hub.docker.com,在Public Repository 中就可以看到上传的镜像。如果要删除上传的镜像,只能在 Docker Hub 界面上操作。
-
这个镜像可被其他 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
- 启动 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
- 通过 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
- 通过 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
- 查看本地镜像
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"]}
- 现在已经可通过 docker pull 从本地 registry 下载镜像了。