使用 docker 的 login 命令之后, 可以使用 push 命令将镜像推送到 dockerhub 上, 但是 dockerhub 毕竟在公网上, 免费的帐户只有一个 private 的 repository 是免费的, 剩下的就都只能做成 public 的. 由于种种限制, 企业私有仓库的创建就有了各种应用场景. 本文将从使用 registry 的方式简单介绍如何搭建私有的 repository.
pull registry 镜像
使用到的 registry 镜像
- [root@liumiaocn ~]# docker search registry |head -n2
- NAME DESCRIPTION STARS OFFICIAL AUTOMATED
- registry Containerized docker registry 1123 [OK]
- [root@liumiaocn ~]# docker pull registry
- Using default tag: latest
- latest: Pulling from library/registry
- c0cb142e4345: Pull complete
- a5002dfce871: Pull complete
- df53ce740974: Pull complete
- 9ce080a7bfae: Pull complete
- 517dc3530502: Pull complete
- Digest: sha256:1cfcd718fd8a49fec9ef16496940b962e30e3927012e851f99905db55f1f4199
- Status: Downloaded newer image for registry:latest
- [root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
docker run 创建私有仓库
registry 的介绍提到的最佳实践建议将 registry 作为容器运行起来.
- [root@liumiaocn ~]# docker run -d -p 5000:5000 registry
- badf822f34751979e4f7fc513b40177f941b227c7385245ad2f391737587b117
- [root@liumiaocn ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- badf822f3475 registry "/entrypoint.sh /etc/" 3 seconds ago Up 2 seconds 0.0.0.0:5000->5000/tcp sharp_khorana
- [root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
向私有仓库 push 一个镜像
准备: pull 一个 busybox
- [root@liumiaocn ~]# docker pull busybox
- Using default tag: latest
- latest: Pulling from library/busybox
- 56bec22e3559: Pull complete
- Digest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912
- Status: Downloaded newer image for busybox:latest
- [root@liumiaocn ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- busybox latest e02e811dd08f 9 days ago 1.093 MB
- registry latest 541a6732eadb 3 weeks ago 33.27 MB
- [root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
准备: tag busybox
- [root@liumiaocn ~]# docker tag busybox localhost:5000/busybox
- [root@liumiaocn ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- busybox latest e02e811dd08f 9 days ago 1.093 MB
- localhost:5000/busybox latest e02e811dd08f 9 days ago 1.093 MB
- registry latest 541a6732eadb 3 weeks ago 33.27 MB
- [root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
push 推送到私有仓库
- [root@liumiaocn ~]# docker push localhost:5000/busybox
- The push refers to a repository [localhost:5000/busybox]
- e88b3f82283b: Pushed
- latest: digest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912 size: 527
- [root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
结果确认
- [root@liumiaocn ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- busybox latest e02e811dd08f 9 days ago 1.093 MB
- localhost:5000/busybox latest e02e811dd08f 9 days ago 1.093 MB
- registry latest 541a6732eadb 3 weeks ago 33.27 MB
- [root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
从私库中 pull 镜像
事前准备: 将其他镜像都删除, 以便确认该镜像确实是从私有仓库中 pull 出来的
- [root@liumiaocn ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- registry latest 541a6732eadb 3 weeks ago 33.27 MB
- [root@liumiaocn ~]#
- 1
- 2
- 3
- 4
pull 私库镜像
- [root@liumiaocn ~]# docker pull localhost:5000/busybox
- Using default tag: latest
- latest: Pulling from busybox
- 56bec22e3559: Pull complete
- Digest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912
- Status: Downloaded newer image for localhost:5000/busybox:latest
- [root@liumiaocn ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- localhost:5000/busybox latest e02e811dd08f 9 days ago 1.093 MB
- registry latest 541a6732eadb 3 weeks ago 33.27 MB
- [root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
确认:
pull 下来的 image 可以正常使用
- [root@liumiaocn ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- localhost:5000/busybox latest e02e811dd08f 9 days ago 1.093 MB
- registry latest 541a6732eadb 3 weeks ago 33.27 MB
- [root@liumiaocn ~]# docker run -it localhost:5000/busybox /bin/sh
- / # hostname
- 24976e98919e
- / #
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
registry 可以用来创建私有仓库, 但是其用户管理 / 图形界面等等方面的功能几乎没有, 很不友好, 之前我们也介绍过 habor,habor 也是建立在 registry 基础之上的, 在接下来的文章中我们会介绍一下如何使用 habor.
来源: http://www.bubuko.com/infodetail-2911729.html