1. 程式人生 > >docker基礎 私有倉庫repository搭建(1) registry

docker基礎 私有倉庫repository搭建(1) registry

ttr def ffi gis label mes 等等 建立 serve

使用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。

再分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!https://www.cnblogs.com/captainbed

docker基礎 私有倉庫repository搭建(1) registry