设置docker本地镜像仓库

1、部署docker registry
1.1 拉取registry镜像
#docker pull docker.io/registry
Trying to pull repository docker.io/library/registry ...
sha256:0e40793ad06ac099ba63b5a8fae7a83288e64b50fe2eafa2b59741de85fd3b97: Pulling from docker.io/library/registry
b7f33cc0b48e: Pull complete
46730e1e05c9: Pull complete 458210699647: Pull complete
0cf045fea0fd: Pull complete
b78a03aa98b7: Pull complete
Digest: sha256:0e40793ad06ac099ba63b5a8fae7a83288e64b50fe2eafa2b59741de85fd3b97
Status: Downloaded newer image for docker.io/registry:latest

1.2 启动registry
#docker run -d -p 5000:5000 --name=registry --restart=always --privileged=true --log-driver=none -v /data/registrydata:/tmp/registry registry
其中,/data/registrydata是一个比较大的系统分区,今后镜像仓库中的全部数据都会保存在这个目录下。
设置主机名字解析
如果有内部dns则可以在dns上配置解析,如果没有则配置host文件

3、更改名称并推送

#docker tag docker.io/registry dockeregistry:5000/registry:latest
#docker tag registry.access.redhat.com/rhel7/pod-infrastructure:latest dockeregistry:5000/pod-infrastructure:latest
#docker push dockeregistry:5000/registry:latest

docker push dockeregistry:5000/pod-infrastructure

在这里一般会报:Get https://dockeregistry:5000/v1/_ping: http: server gave HTTP response to HTTPS client的错误
解决办法:修改/etc/docker/daemon.json,在里面添加:{ "insecure-registries":["dockeregistry:5000"] }

重启docker

验证
4.1、修改客户端hosts文件,在里面添加仓库主机记录

4.2、修改docker配置文件

4.3、重启docker
4.4、从仓库拉取镜像

验证正确 ,配置完成