docker registry私有仓库搭建

构建环境:centos 7.8
docke版本:17.03.3-ce
registry版本:latest
registry私有仓库地址:192.168.126.134

1.拉取最新镜像
docker pull registry

2.使用httpd的加密工具htpasswd生成登陆信息加密文件htpasswd
mkdir -p /docker/auth
cd /docker
docker run --entrypoint /usr/bin/htpasswd registry -Bbn admin 123456 > auth/htpasswd

3.查看htpasswd文件信息内容如下:
admin:$2y$05$L95OarhZB1heGjWrqODDDOajuLzE9mFgYIHGLGnhgfdkdB8OYBl4W

4使用htpasswd认证、registry镜像创建仓库容器:myregistry1
docker run -d -p 5001:5000 --restart=always --name myregistry -v /docker/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry

5.查看容器是否创建成功
docker ps
ss -tnl | grep 5001

6.创建成功后,修改/lib/systemd/system/docker.service 配置信息,在ExecStart=/usr/bin/dockerd 该行末尾添加 --insecure-registry 192.168.126.134:5001,如果没有添加,会产生如下报错:Get https://192.168.126.134:5001v1/_ping: http: server gave HTTP response to HTTPS client

7.重启docker服务
systemctl daemon-reload
systemctl restart docker

7.进行功能验证
使用admin登陆仓库:
docker login --username=admin 192.168.126.134:5001
给本地镜像nginx:v2 打标签:
docker tag nginx:v2 192.168.126.134:5001/nginx:v2
推送镜像到私有仓库:
docker push 192.168.126.134:5001/nginx:v2
删除本地192.168.126.134:5001/nginx:v2镜像:
docker rmi 192.168.126.134:5001/nginx:v2
从私有仓库拉取镜像:
docker pull 192.168.126.134:5001/nginx:v2

你可能感兴趣的:(docker,linux,java,nginx,centos)