docker構建私有倉庫並設置倉庫用戶和密碼


一、docker構建私有倉庫

#搭建私有鏡像倉庫
[root@docker_test opt]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
Get https://registry-1.docker.io/v2/library/registry/manifests/sha256:b1165286043f2745f45ea637873d61939bff6d9a59f76539d6228abf79f87774: net/http: TLS handshake timeout

#查看鏡像
[root@docker_test opt]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
nginx                          v1                  6282d012bf54        About an hour ago   446MB
mysql                          latest              990386cbd5c0        2 weeks ago         443MB
richarvey/nginx-php-fpm        latest              3fd3101af9bd        2 weeks ago         328MB
192.168.56.60:5000/centos7.0   v1                  9f38484d220f        2 months ago        202MB
centos                         7                   9f38484d220f        2 months ago        202MB
registry                       latest              f32a97de94e1        2 months ago        25.8MB

#創建文件夾,往文件中添加密碼
[root@docker_test opt]# cd /opt/
[root@docker_test opt]# mkdir auth
[root@docker_test opt]# cd /opt/auth/
[root@docker_test opt]# ll
total 0
drwxr-xr-x 2 root root 22 May 26 15:02 auth
drwx--x--x 4 root root 28 May 26 09:40 containerd
drwxr-xr-x 2 root root  6 May 26 14:53 registry
[root@docker_test opt]# cd auth/

[root@docker_test auth]# echo "user:nulige passwd:123456" >htpasswd
[root@docker_test auth]# cd ..
[root@docker_test opt]# ll
total 0
drwxr-xr-x 2 root root 22 May 26 15:05 auth
drwx--x--x 4 root root 28 May 26 09:40 containerd
drwxr-xr-x 2 root root  6 May 26 14:53 registry

#格式轉換
[root@docker_test opt]# docker run --entrypoint htpasswd registry:latest -Bbn nulige 123456 >auth/htpasswd

[root@docker_test opt]# ll
total 0
drwxr-xr-x 2 root root 22 May 26 15:05 auth
drwx--x--x 4 root root 28 May 26 09:40 containerd
drwxr-xr-x 2 root root  6 May 26 14:53 registry

[root@docker_test opt]# cat auth/htpasswd 
nulige:$2y$05$9lG7QFC/hSCj/s.c4769K.4mSsqWF5OwTPv2UP6.itFGlWCV/HwVS

#啟動registry1容器 ,默認端口5000映射到5000
docker run  -d -p 5000:5000 --restart=always --name registry1 \
     -v `pwd`/auth:/auth \
     -e "REGISTRY_AUTH=htpasswd" \
     -e  "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
     -e  REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
     registry

#配置使用私有倉庫
[root@docker_test ~]# cat /etc/docker/daemon.json 
{
"insecure-registries":["127.0.0.1:5000"]
}

#重啟服務
systemctl restart docker

#登錄鏡像倉庫
[root@docker_test opt]# docker login 127.0.0.1:5000
Username: nulige
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

#給鏡像打tag
[root@docker_test opt]# docker tag richarvey/nginx-php-fpm:latest 127.0.0.1:5000/nulige/nginx
[root@docker_test opt]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
nginx                          v1                  6282d012bf54        2 hours ago         446MB
mysql                          latest              990386cbd5c0        2 weeks ago         443MB
127.0.0.1:5000/nulige/nginx    latest              3fd3101af9bd        2 weeks ago         328MB
richarvey/nginx-php-fpm        latest              3fd3101af9bd        2 weeks ago         328MB
192.168.56.60:5000/centos7.0   v1                  9f38484d220f        2 months ago        202MB
centos                         7                   9f38484d220f        2 months ago        202MB
registry                       latest              f32a97de94e1        2 months ago        25.8MB

#上傳鏡像
[root@docker_test opt]# docker push 127.0.0.1:5000/nulige/nginx
The push refers to repository [127.0.0.1:5000/nulige/nginx]
eec165118982: Pushed 
353ba0871334: Pushed 
679c6ac9bd06: Pushed 
3ddda5f15575: Pushed 
a2cb1314b8cd: Pushed 
45a48afbef6b: Pushed 
21791e460009: Pushed 
3f8a198a5690: Pushed 
6ace97c9dd6b: Pushed 
a0279b0ac758: Pushed 
79a735cb2096: Pushed 
a464c54f93a9: Pushed 
latest: digest: sha256:4f914a0c9d25066eaf7cdd734452803ec307ad82605cbdb98d0bc57ba84603e2 size: 6364

#查看鏡像
[root@docker_test opt]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
registry                       latest              f32a97de94e1        2 months ago        25.8MB
127.0.0.1:5000/nulige/nginx    latest              3fd3101af9bd        2 weeks ago         328MB

#刪除鏡像
[root@docker_test opt]# docker rmi -f 3fd3101af9bd
Untagged: 127.0.0.1:5000/nulige/nginx:latest
Untagged: 127.0.0.1:5000/nulige/nginx@sha256:4f914a0c9d25066eaf7cdd734452803ec307ad82605cbdb98d0bc57ba84603e2
Untagged: richarvey/nginx-php-fpm:latest
Untagged: richarvey/nginx-php-fpm@sha256:4f914a0c9d25066eaf7cdd734452803ec307ad82605cbdb98d0bc57ba84603e2
Deleted: sha256:3fd3101af9bdb10dd6b84e121c06abddf1d2ca29543e608bae3a12d6dae1d797

#從私有倉庫中下載鏡像
[root@docker_test opt]# docker pull 127.0.0.1:5000/nulige/nginx:latest
latest: Pulling from nulige/nginx
bdf0201b3a05: Already exists 
ea6e561c50e0: Already exists 
f581654c6ada: Already exists 
f205a7399250: Already exists 
4dba97d8c6bd: Already exists 
9042ecea402d: Already exists 
bfbd0774205d: Already exists 

#查看鏡像
[root@docker_test opt]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
nginx                         v1                  6282d012bf54        2 hours ago         446MB
mysql                         latest              990386cbd5c0        2 weeks ago         443MB
127.0.0.1:5000/nulige/nginx   latest              3fd3101af9bd        2 weeks ago         328MB
centos                        7                   9f38484d220f        2 months ago        202MB
registry                      latest              f32a97de94e1        2 months ago        25.8MB

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM