http://www.cnblogs.com/womars/p/5906410.html
接着上篇,上面为上篇地址。
#通过docker tag将该镜像标志为要推送到私有仓库
[[email protected]2 ~]# sudo docker tag ubuntu 192.168.0.34:5000/ubuntu Error response from daemon: no such id: ubuntu [[email protected]-2 ~]# sudo docker tag docker.io/ubuntu 192.168.0.34:5000/ubuntu Error response from daemon: no such id: docker.io/ubuntu [[email protected]-2 ~]# sudo docker tag 3876b81b5a81 192.168.0.34:5000/ubuntu
#查看镜像
[[email protected]2 ~]# docker images 192.168.0.34:5000/ubuntu latest 3876b81b5a81 7 months ago 187.9 MB docker.io/ubuntu 14.04.3 3876b81b5a81 7 months ago 187.9 MB
#提交ubuntu镜像到私有仓库
[[email protected]2 ~]# sudo docker push 192.168.0.34:5000/ubuntu The push refers to a repository [192.168.0.34:5000/ubuntu] 5f70bf18a086: Pushed 0d81735d8272: Pushed 982549bd6b32: Pushed 8698b31c92d5: Pushed latest: digest: sha256:a47804d268c600572aab1f564e38d1ef009bd7c7ce4bbd325be51973541e5431 size: 1129
#进入容器
[[email protected]2 data]# docker exec -it 6cb333619b90 /bin/sh / # ls bin entrypoint.sh home linuxrc mnt root sbin sys usr dev etc lib media proc run srv tmp var / # cd /tmp/registry/ /tmp/registry # ls /tmp/registry #
发现还是没有镜像
#镜像在容器的/var/lib/registry目录下
~ # cd /var/lib/registry/docker/registry/v2/repositories/ /var/lib/registry/docker/registry/v2/repositories # ls busybox nginx ubuntu /var/lib/registry/docker/registry/v2/repositories # ll /bin/sh: ll: not found /var/lib/registry/docker/registry/v2/repositories # ls -l total 0 drwxr-xr-x 5 root root 52 Sep 8 06:46 busybox drwxr-xr-x 5 root root 52 Sep 8 09:04 nginx drwxr-xr-x 5 root root 52 Sep 8 09:04 ubuntu /var/lib/registry/docker/registry/v2/repositories #
#切换映射目录
[[email protected]2 registry]# docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry docker.io/registry bc2304a84ec4cd7eed6b0dabd929141990d2e4f11253941a1fe28856c255aa06 [[email protected]-2 registry]# docker push 192.168.0.34:5000/busybox The push refers to a repository [192.168.0.34:5000/busybox] 8ac8bfaff55a: Retrying in 1 seconds Received unexpected HTTP status: 500 Internal Server Error
问题:push镜像报错。
#解决办法:
给这个容器扩展的特权--privileged=true
[[email protected]2 registry]# docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry --privileged=true docker.io/registry 23397ef79ec57f6a077dd50c8ff449c3a1dd6b21b8c13f6e210775ec0975412e
注:这儿只有加特权才可行,后面我用了registry:2镜像没有这个问题了,估计是最新版本镜像的问题吧。
#提交镜像到本地仓库中
[[email protected]2 registry]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.0.34:5000/busybox latest 2b8fd9751c4c 11 weeks ago 1.093 MB [[email protected]-2 registry]# docker push 192.168.0.34:5000/busybox The push refers to a repository [192.168.0.34:5000/busybox] 8ac8bfaff55a: Pushed latest: digest: sha256:a59906e33509d14c036c8678d687bd4eec81ed7c4b8ce907b888c607f6a1e0e6 size: 505
发现可以push上去了。
[[email protected]2 registry]# ls /opt/data/registry/docker/registry/v2/repositories/ Busybox [[email protected]-2 registry]# curl -XGET 192.168.0.34:5000/v2/_catalog {"repositories":["busybox"]}
#进入容器看一下镜像实际存储位置
[[email protected]2 registry]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 23397ef79ec5 docker.io/registry "/entrypoint.sh /etc/" 15 minutes ago Up 15 minutes 0.0.0.0:5000->5000/tcp berserk_hypatia [[email protected]-2 registry]# docker exec -it 23397ef79ec5 /bin/sh / # ls bin entrypoint.sh home linuxrc mnt root sbin sys usr dev etc lib media proc run srv tmp var / # cd /var/lib/registry/docker/registry/v2/repositories/ /var/lib/registry/docker/registry/v2/repositories # ls busybox
#查看镜像的存储目录树
[[email protected]2 registry]# tree /opt/data/registry/docker/registry/v2/repositories/ /opt/data/registry/docker/registry/v2/repositories/ └── busybox ├── _layers │ └── sha256 │ ├── 2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749 │ │ └── link │ └── 8ddc19f16526912237dd8af81971d5e4dd0587907234be2b83e249518d5b673f │ └── link ├── _manifests │ ├── revisions │ │ └── sha256 │ │ └── a59906e33509d14c036c8678d687bd4eec81ed7c4b8ce907b888c607f6a1e0e6 │ │ └── link │ └── tags │ └── latest │ ├── current │ │ └── link │ └── index │ └── sha256 │ └── a59906e33509d14c036c8678d687bd4eec81ed7c4b8ce907b888c607f6a1e0e6 │ └── link └── _uploads 16 directories, 5 files
测试放到下篇。
http://www.cnblogs.com/womars/p/5906444.html
时间: 2024-10-12 11:57:33