仓库机:用作私有仓库的服务器机器
客户机:需要拉取镜像的机器
1.拉取基础仓库镜像:
docker pull registry:2
2.设置私有仓库地址
vim /etc/docker/daemon.json
{
"insecure-registries": ["作为仓库的ip:5000"], ##添加此行内容,不要漏掉逗号
"registry-mirrors": ["https://oxxxxxt.mirror.aliyuncs.com"] ##此处为之前配置的阿里云镜像加速地址
}
- 保存并重启docker(这一步会导致正在运行的docker容器失效,注意)
systemctl daemon-reload
systemctl restart docker
-
后台运行仓库容器(第4步可以放到第2步做,那就省去第5步)
docker run -d -p 5000:5000 --restart=always --name registry registry:2
-
重新加载配置
systemctl daemon-reload
浏览器访问http://作为仓库的ip:5000/v2/_catalog
- 验证上传下载镜像:
6.1docker pull hello-world
6.2docker tag hello-world:latest 127.0.0.1:5000/hello-world:latest
(本机:127.0.0.1 客户机:则用你的仓库机外部ip地址)
6.3docker push 127.0.0.1:5000/hello-world:latest