Docker本地私有倉庫的建立
環境:
192.168.139.26 docker的客戶端
192.168.139.52 docker的服務器端(倉庫所在位置)
首先在192.168.139.52上下載registry鏡像
[email protected]:~$ sudo docker pull registry
下面操作在192.168.139.52完成
默認情況下會將倉庫存放於容器內的/tmp/registry目錄下,這樣如果容器被刪除,則存放於容器中的鏡像也會丟失,所以我們一般情況下會指定本地一個目錄掛載到容器內的/tmp/registry下,並用registry鏡像創建創建並啟動一個容器,如下:
[email protected]
6bd275a34ad9130aeb146d8761f6002a512df48308e6836655abea0754322e0a
下面操作在192.168.139.26完成
[email protected]:~$ sudo docker ps #查看本機當前運行的容器,只有registry容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6bd275a34ad9 registry "/entrypoint.sh /e..." 22 seconds ago Up 19 seconds 0.0.0.0:5000->5000/tcp distracted_almeida
[email protected]:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-ubuntu latest 14f60031763d 11 days ago 120MB
[email protected]:~$ sudo docker tag my-ubuntu:latest 192.168.139.52:5000/u_bantu
[email protected]:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.139.52:5000/u_bantu latest 14f60031763d 11 days ago 120MB
my-ubuntu latest 14f60031763d 11 days ago 120MB
[email protected]:~$ sudo docker push 192.168.139.52:5000/u_bantu
The push refers to a repository [192.168.139.52:5000/u_bantu]
26b126eb8632: Pushed
220d34b5f6c9: Pushed
8a5132998025: Pushed
aca233ed29c3: Pushed
e5d2f035d7a4: Pushed
latest: digest: sha256:84c334414e2bfdcae99509a6add166bbb4fa4041dc3fa6af08046a66fed3005f size: 1357
將兩個鏡像全部刪除
[email protected]:~$ sudo docker rmi my-ubuntu
[email protected]:~$ sudo docker rmi 14f60031763d
從192.169.139.52服務器(本地私有倉庫上重新下載)
[email protected]:~$ docker pull 192.168.139.52:5000/u_bantu
Using default tag: latest
latest: Pulling from u_bantu
e0a742c2abfd: Pull complete
486cb8339a27: Pull complete
dc6f0d824617: Pull complete
4f7a5649a30e: Pull complete
672363445ad2: Pull complete
Digest: sha256:84c334414e2bfdcae99509a6add166bbb4fa4041dc3fa6af08046a66fed3005f
Status: Downloaded newer image for 192.168.139.52:5000/u_bantu:latest
可以看到直接從192.169.139.52服務器(本地私有倉庫)下載成功
[email protected]:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.139.52:5000/u_bantu latest 14f60031763d 11 days ago 120MB
下面操作在192.169.139.52完成
在192.169.139.52上可以看到沒有192.168.139.52:5000/u_bantu 鏡像
[email protected]:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 751f286bc25e 11 days ago 33.2MB
直接從192.169.139.52服務器(本機)下載
[email protected]:~$ sudo docker pull 192.168.139.52:5000/u_bantu
Using default tag: latest
latest: Pulling from u_bantu
e0a742c2abfd: Pull complete
486cb8339a27: Pull complete
dc6f0d824617: Pull complete
4f7a5649a30e: Pull complete
672363445ad2: Pull complete
Digest: sha256:84c334414e2bfdcae99509a6add166bbb4fa4041dc3fa6af08046a66fed3005f
Status: Downloaded newer image for 192.168.139.52:5000/u_bantu:latest
可以看到下載成功
[email protected]:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 751f286bc25e 11 days ago 33.2MB
192.168.139.52:5000/u_bantu latest 14f60031763d 11 days ago 120MB
這樣在192.168.139.52服務器上創建本地私有倉庫成功,只要可以訪問192.168.139.52:5000端口的主機都可以直接在此倉庫下載此倉庫已經有的鏡像
本文出自 “11097124” 博客,請務必保留此出處http://11107124.blog.51cto.com/11097124/1952806
Docker本地私有倉庫的建立