一、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:liuys 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 liuys 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: liuys

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

先拉取一个nginx做测试

[root@localhost opt]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
fc7181108d40: Pull complete 
d2e987ca2267: Pull complete 
0b760b431b11: Pull complete 
Digest: sha256:48cbeee0cb0a3b5e885e36222f969e0a2f41819a68e07aeb6631ca7cb356fed1
Status: Downloaded newer image for nginx:latest
 

[root@docker_test opt]# docker tag nginx:latest 127.0.0.1:5000/liuys/nginx

 

#上传镜像

[root@docker_test opt]# docker push 127.0.0.1:5000/liuys/nginx

The push refers to repository [127.0.0.1:5000/liuys/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/liuys/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

 

二、构建图形登陆界面

#启动镜像

[root@localhost opt]# docker run -d -e ENV_DOCKER_REGISTRY_HOST=192.168.75.130 -e ENV_DOCKER_REGISTRY_PORT=5000 -p 80:80 konradkleine/docker-registry-frontend:v2

浏览器登录输入账号密码

至此镜像库部署完毕

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐