1、使用registry映象建立私有倉庫
安裝Docker後,可以通過官方提供的registry映象來簡單搭建一套本地私有倉庫環境:
docker run -d -p 5000:5000 registry
這條命令將自動下載並啟動一個registry容器,建立本地的私有倉庫服務。預設會將倉庫建立在容器的/tmp/registry目錄下。可以通過-v引數來將映象檔案存放在本地指定路徑
例如:將上傳的映象放到/opt/data/registry目錄:
docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
此時將在本地建立一個私有倉庫服務,監聽埠為5000。
2.管理私有倉庫
docker本地私有倉庫地址為10.0.0.32:5000
首先在客戶端檢視本地映象:
[root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 16.04 20c44cd7596f 11 days ago 123MB ubuntu latest 20c44cd7596f 11 days ago 123MB centos latest d123f4e55e12 3 weeks ago 197MB [root@docker ~]#
將映象通過docker tag修改映象標籤為10.0.0.32:5000/test:
[root@docker ~]# docker tag ubuntu:16.04 10.0.0.32:5000/test [root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.32:5000/test latest 20c44cd7596f 11 days ago 123MB ubuntu 16.04 20c44cd7596f 11 days ago 123MB ubuntu latest 20c44cd7596f 11 days ago 123MB centos latest d123f4e55e12 3 weeks ago 197MB [root@docker ~]#
由於docker倉庫與客戶端的https問題,需要修改/usr/lib/systemd/system/docker.service檔案,新增 ExecStart=/usr/bin/dockerd --registry-mirror=https://1y8rn456.mirror.aliyuncs.com --insecure-registry 10.0.0.32:5000之後需要重啟docker。
使用docker push將映象上傳到私有倉庫:
[root@docker docker]# docker push 10.0.0.32:5000/test The push refers to a repository [10.0.0.32:5000/test] 2f5b0990636a: Pushed c9748fbf541d: Pushed b3968bc26fbd: Pushed aa4e47c45116: Pushed 788ce2310e2f: Pushed latest: digest: sha256:d4558f7616365813792918b6d73dc474bcacf99b13d1ed947731a653fb6e260c size: 1357
拉取私有倉庫映象:
[root@docker docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 16.04 20c44cd7596f 11 days ago 123MB ubuntu latest 20c44cd7596f 11 days ago 123MB centos latest d123f4e55e12 3 weeks ago 197MB [root@docker docker]# [root@docker docker]# docker pull 10.0.0.32:5000/test Using default tag: latest latest: Pulling from test Digest: sha256:d4558f7616365813792918b6d73dc474bcacf99b13d1ed947731a653fb6e260c Status: Downloaded newer image for 10.0.0.32:5000/test:latest [root@docker docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.32:5000/test latest 20c44cd7596f 11 days ago 123MB ubuntu 16.04 20c44cd7596f 11 days ago 123MB ubuntu latest 20c44cd7596f 11 days ago 123MB centos latest d123f4e55e12 3 weeks ago 197MB [root@docker docker]#