1.about theRegistry
The official Docker hub is a great place to manage the public image, we can find the image we want on it, or we can push our own image. However, sometimes our usage scenarios require that we have a private mirrored repository to manage our own mirrors. This can be achieved through open source software Registry .
Registryin theGitHubThere are two codes on the list:Old code base and new code base. The old code is usedpythonwritten, exist Pulland thePushthe performance issues, out to0.9.1after the version is marked asdeprecated, and no further development. From2.0The version begins with the development of the new code base and the new code base isGolanguage written, modified mirrorIDthe generation algorithm,Registrythe image preservation structure greatly optimizes the Pulland thePushthe efficiency of the mirror.
The official image of the registry is provided on the Docker hub (details), and we can use the registry image directly to build a container, Build our own private warehouse services. the registry image of the Tag latest is 0.9.1 Version, we use the 2.1.1 version directly.
2. Registrythe deployment
Run the following command to get the registry image,
sudo Docker pull registry:2.1. 1
Then start a container,
sudo --restart=always: --name Registry registry:2.1. 1
The Registry service defaults to storing the uploaded image in the container's /var/lib/registry, and we mount the host's /opt/registry directory to that directory , it is possible to save the image to the host's /opt/registry directory.
Run Docker PS and look at the container,
[email protected] ~ $ sudo docker ps 2.1
. 1 /bin /REGISTRY/ETC/D 46 seconds ago U P 45 seconds 0.0 : 5000 ->5000 /tcp Registry
Instructions we have started the registry Service, open the browser input http://127.0.0.1:5000/v2, the following situation is shown registry Run Normally,
3.Validation
Now we can verify this by pushing the image to registry .
There's a hello-world image on my machine , and we're going to use docker tag to flag the image as being pushed to a private warehouse.
sudo 127.0. 0.1:/hello-world
Then look at the following local mirrors,
[Email protected] ~ $sudoDocker imagesrepository TAG IMAGE ID CREATED VIRTUAL Sizereg Istry2.1.1b91f745cd2335Days ago220.1Mbubuntu14.04A5a467fddcb86Days ago187.9Mbhello-world Latest 975B84D108F12Weeks ago960B127.0.0.1: the/hello-world Latest 975B84D108F12Weeks ago960B
Next, we run docker push hello-world mirror push to our private warehouse,
[email protected] ~ $ sudo Docker push . 0.1 : 5000 /hello- worldthe push refers to a repository [ 127.0 . 0.1 : 5000 /hello-world] (len: 1 ) 975b84d108f1:image successfully pushed 3f12c794407e:image successfully Pushed latest:digest:sha256:1c7adb1ac65df0bebb40cd4a84533f787148b102684b74cb27a1982967008e4b size: 2744
Now we can look at our local /opt/registry directory that has just been pushed up to the hello-world. We also enter Http://127.0.0.1:5000/v2/_catalog in the browser , as shown in
Now we can remove our local 127.0.0.1:5000/hello-world and Hello-world first ,
sudo docker rmi hello-sudo127.0. 0.1:/hello-world
Then use Docker pull to get the hello-world image from our private warehouse ,
[Email protected] ~ $sudoDocker pull127.0.0.1: the/hello-worldusing default tag:latestlatest:Pulling from Hello-worldb901d36b6f2f:pull Complete 0a6ba66e537a:pull complete digest:sha256 : 1c7adb1ac65df0bebb40cd4a84533f787148b102684b74cb27a1982967008e4bstatus:downloaded Newer image for 127.0.0.1: the/hello-World:latest[email protected]-COMPAQ-PRESARIO-CQ35-NOTEBOOK-PC ~ $sudoDocker imagesrepository TAG IMAGE ID CREATED VIRTUAL Sizereg Istry2.1.1b91f745cd2335Days ago220.1Mbubuntu14.04A5a467fddcb86Days ago187.9MB127.0.0.1: the/hello-world Latest 0a6ba66e537a2Weeks ago960B
4.Possible problems
There may be an issue where you cannot push mirroring to a private warehouse. This is because the registry service We started is not secure and trustworthy. This is what we need to modify the Docker configuration file /etc/default/docker, add the following content,
docker_opts= "--insecure-registry xxx.xxx.xxx.xxx:5000"
Then restart the Docker daemon process,
sudo service docker restart
This is the push again .
(done)
* * Version statement: This blog post for the original, if you want to reprint, please ask the blogger to agree beforehand.
Construction verification of Docker private warehouse registry