docker registry to build a private warehouse
Preparation
- A host (192.168.65.128) based on centos and installed docker environment as a private warehouse server
- A host (192.168.65.130) based on centos and installed docker environment is used as a test machine to test submission and pull the image of the private warehouse server
officially built
Private warehouse server (192.168.65.128)
-
Download mirror registry
docker pull registry
-
run registry
docker run -itd -v /data/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:latest
Parameter Description:
- -itd: Open a pseudo-terminal in the container for interactive operation and run in the background;
- -v: Bind the /data/registry directory of the host to the container /var/lib/registry directory (this directory is the directory where mirror files are stored in the registry container) to achieve data persistence;
- -p: port mapping; access to port 5000 of the host machine will access the service of the registry container;
- –restart=always: This is the restart strategy, if the container exits abnormally, it will automatically restart the container;
- –name registry: Create a container named registry, you can name it whatever you want;
- registry:latest: This is the image that was pulled just now.
-
View all images in the private warehouse (there is no mirror image in the warehouse at this time, so the result is empty)
curl http://127.0.0.1:5000/v2/_catalog
Available data:
{“repositories”:[]}
Test machine (192.169.65.130)
-
Add private storage server address
vim /etc/docker/daemon.json
{ "registry-mirrors": [ "https://registry.docker-cn.com"], "insecure-registries": [ "192.168.65.128:5000"] }
Parameter Description
insecure_registries: Here is the private warehouse server address
Restart the docker service
systemctl restart docker
Upload the image to the private warehouse server (192.168.65.128)
-
Pull the hello-world image (this image is docker hub image)
docker pull hello-world
-
Label the hello-world image
docker tag hello-world:latest 192.168.65.128:5000/hello:v1
The format is:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Parameter Description:
- SOURCE_IMAGE --> hello-world
- [:TAG] --> latest
- TARGET_IMAGE --> 192.168.65.128:5000/hello
- [:TAG] --> v1
Notice:
192.168.65.128:5000/hello is the address of the private warehouse server (192.168.65.128) plus the name of the image you want to upload to the server (this name can be chosen)
-
Upload the image hello:v1 to the private warehouse server (192.168.65.128)
docker push 192.168.65.128:5000/hello:v1
-
Check whether the private warehouse server (192.168.65.128) already has a hello:v1 image
curl http://127.0.0.1:5000/v2/_catalog
got the answer:
{“repositories”:[“hello”]}
Pull the image from the private warehouse server (192.168.65.128)
-
Delete the hello:v1 image on the test machine (192.168.65.130)
docker rmi 192.168.65.128:5000/hello:v1
-
Pull the image on the private warehouse server (192.168.65.128)
docker pull 192.168.65.128:5000/hello:v1