Docker builds a private warehouse
1 Build a private warehouse
The ip address used below refers to the address of the local machine, which can be viewed by the following command:
$ ip addr
Now start to build a private warehouse: since the registry is also a mirror, we pull it and start a container. Port mapping via 5000:5000.
# 1.拉取私有仓库镜像
sudo docker pull registry
# 2.启动私有仓库容器,宿主机port:容器port
sudo docker run -id --name=registry -p 5000:5000 registry
Then open the browser, enter the following URL, and replace the ip with the local address:
# 3.打开浏览器,输入:http://ip:5000/v2/_catalog
# 看到{"repositories":[]}表示私有仓库搭建成功
Next, we need to trust the private warehouse, and replace the ip with the local address:
# 4.修改daemon.json
sudo vim /etc/docker/daemon.json
# 在该文件中添加一个key即可,用于让docker信任私有仓库地址
# {"insecure-registries": ["ip:5000"]}
If you want to use multiple private repositories, separate them with commas, for example: ["ip1:port1", "ip2:port2"]
Finally restart the docker service:
# 5.重启docker服务
systemctl restart docker
sudo docker start registry
2 Upload the image to the private warehouse
# 1.标记镜像为私有仓库的镜像
sudo docker tag <IMAGE:TAG> ip:5000/<IMAGE:TAG>
# 2.上传标记的镜像
sudo docker push ip:5000/<IMAGE:TAG>
3 Pull the image from the private warehouse
# 拉取镜像
sudo docker pull ip:5000/<IMAGE:TAG>