docker 私有倉庫搭建

 

以docker 方式安裝

docker pull registry

  

1、創建文件夾,往文件中添加密碼

 

[root@localhost ~]# cd /data/docker/auth
[root@localhost /data/docker/auth]# echo "user:lulu passwd:123456" >htpasswd
#格式轉換
[root@localhost /data/docker/auth]# cd ..
[root@localhost /data/docker]# docker run --entrypoint htpasswd registry:latest -Bbn lulu 123456 >auth/htpasswd

[root@localhost /data/docker]# cat auth/htpasswd 
lulu:$2y$05$9lG7QFC/hSCj/s.c4769K.4mSsqWF5OwTPv2UP6.itFGlWCV/HwVS\

  

 

2、運行容器 

[root@localhost /data/docker]# cd /

  

[root@localhost ~]# docker run -d -p 5000:5000 --restart unless-stopped --privileged=true \
-v /data/docker/history:/data/registry \
-v `pwd`/data/docker/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e  "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e  REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
registry

  

 

登錄鏡像倉庫

[root@localhost /]#  docker login 127.0.0.1:5000
Username: lulu
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded

  

查看私庫中的鏡像

curl -XGET http://192.168.182.100:5000/v2/_catalog

  

查看某一鏡像的版本信息 訪問方式爲 http://ip:port/v2/鏡像名字/tags/list 

 curl -XGET http://192.168.1.203:5000/v2/myserver/tags/list

  

刪除鏡像

刪除鏡像對應的API如下:

[root@master ~]# docker exec -it f70d0c79e6d546d4 sh

  DELETE /v2/<name>/manifests/<reference>

name:鏡像名稱

reference: 鏡像對應sha256值

 

將鏡像push到私庫在其他節點 使用私庫鏡像時需要跟上對應的ip,端口和鏡像在私庫中的名字和版本

#修改標籤
docker tag nginx 192.168.1.200:5000//myserver:v1
#push 上傳
docker push 192.168.1.200:5000//myserver:v1

  

要使用非http的倉庫,所有終端都需求配置一下

vi  /etc/docker/daemon.json

 

沒有配置加速器的

// 單個私服的寫法
{
 "insecure-registries": ["registry的IP地址:端口號"]
}

  

// 多個私服的寫法
{
"insecure-registries": ["registry1的IP地址:端口號","registry2的IP地址:端口號"]
}

  

配置加速器的

// 單個私服的寫法
{
"registry-mirrors": [
"https://dockerhub.azk8s.cn",
"https://reg-mirror.qiniu.com"
],
"insecure-registries": ["registry的IP地址:端口號"]
}

  

// 多個私服的寫法
{
"registry-mirrors":  [
"https://dockerhub.azk8s.cn",
"https://reg-mirror.qiniu.com"
],
 "insecure-registries": ["registry1的IP地址:端口號","registry2的IP地址:端口號"]
}

 

修改完後 重置重啓

systemctl daemon-reload
systemctl restart docker

  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章