In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how Docker manages and deletes images in the local warehouse". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
One: installation of docker private warehouse
1. There is an image repository for downloading images:
[root@localhost ~] # systemctl start docker# if you already have an image, the way to force deletion of the original image is as follows: [root@xxx-pub /] # docker rmi-f docker.io/registryuntagged: docker.io/registry:latestuntagged: docker.io/registry@sha256:51bb55f23ef7e25ac9b8313b139a8dd45baa832943c8ad8f7da2ddad6355b3c8 [root@xxx-pub /] # # start downloading the latest image. [root@localhost ~] # docker pull registryusing default tag: latestlatest: pulling from library/registry4064ffdc82fe: pull complete c12c92d1c5a2: pull complete 4fbc9b6835cc: pull complete 765973b0f65f: pull complete 3968771a7c3a: pull complete digest: sha256:20bbbc0f6384cf7dc6e292ccbe75935b73c92ec776543c970904bc60feceb129status: downloaded newer image for registry:latest [root@localhost ~] #
2. Start and mount the image repository to the local disk:
[root@xxx-pub /] # docker run-d-v / registry:/home/docker-registry-p 5000 restart=always-- privileged=true-- name registry registry:latestunable to find image 'registry:latest' locallytrying to pull repository docker.io/library/registry. Latest: pulling from docker.io/library/registrydigest: sha256:51bb55f23ef7e25ac9b8313b139a8dd45baa832943c8ad8f7da2ddad6355b3c8status: downloaded newer image for docker.io/registry:latestb7bd2b14ed488936afe798be95f3cd56f604fb092d45cf6f4a58359bcad0d34c [root@xxx-pub /] #
-v / registry:/home/docker-registry: by default, the warehouse is stored in the / home/docker-registry directory in the container, and the local directory is specified to mount to the container.
-p 5000Rom 5000: Port mapping. That is, local port 5000, mapped to port 5000 in registry.
-restart=always1: always restart the container when it exits, mainly in the production environment.
-privileged=true: the security module selinux in centos7 disables permissions, and parameters add privileges to the container. Similar permission errors will be reported without passing the image. Oserror: [errno 13] permission denied:'/ tmp/registry/repositories/liibrary') or (received unexpected http status: 500 internal server error)
-name registry: specifies the name of the container.
To persist the data, mount the volume to / home/docker-registry
3. We tag a local image and upload it:
Check which images are available locally:
[root@xxx-pub /] # docker imagesrepository tag image id created sizedocker.io/centos centos7.5.1804 fdf13fa91c6e 4 weeks ago 200 mbdocker.io/registry latest b2b03e9146e1 2 months ago 33.3 mb [root@xxx-pub /] #
Take docker.io/centos as an example.
[root@xxx-pub /] # docker tag fdf13fa91c6e localhost:5000/xxx-centos7.5.1804:1.0##localhost:5000 indicates the address of the repository, fdf13fa91c6e indicates the name of the image, and fdf13fa91c6e indicates the version number. Or: [root@xxx-pub /] # docker tag docker.io/centos:centos7.5.1804 localhost:5000/xxx-centos7.5.1804:1.0
4. Upload directly:
[root@xxx-pub /] # docker push localhost:5000/xxx-centos7.5.1804:1.0the push refers to a repository [localhost:5000/xxx-centos7.5.1804] bcc97fbfc9e1: pushed 1.0: digest: sha256:7c14180942615fef85cb5c8b1388e028be1a8f79694a5fa30a4025173e42ad61 size: 529 [root@xxx-pub /] #
Errors similar to the following may be reported during the push process (the following is an error prompt on the network):
[root@localhost ~] # docker push 192.168.174.128:5000/hello:latestthe push refers to a repository [192.168.174.128:5000/hello] unable to ping registry endpoint https://192.168.174.128:5000/v0/v2 ping attempt failed with error: get https://192.168.174.128:5000/v2/: http: server gave http response to https client v1 ping attempt failed with error: get https://192.168.174.128:5000/v1/_ Ping: http: server gave http response to https client [root@localhost ~] #
Solution:
Use https, modify the / etc/sysconfig/docker file (here is the docker under centos7), and add add_registry='-add-registry 192.168.18.162 docker 5000000 registration registryhorse colors 5000' (above is the configuration of the historical docker version), as shown below:
However, in the configuration of the new docker container repository, the configuration in its own docker container is adopted (here, the following configuration is specified on both docker registry and other pull images):
After the specification is completed, restart docker. The configuration for restart is as follows:
[root@youx-pub volumes] # systemctl restart docker
In addition: check docker.service, check the configuration file:
[root@youx-pub registry] find /-name docker.service/sys/fs/cgroup/memory/system.slice/docker.service/sys/fs/cgroup/devices/system.slice/docker.service/sys/fs/cgroup/blkio/system.slice/docker.service/sys/fs/cgroup/cpu Cpuacct/system.slice/docker.service/sys/fs/cgroup/pids/system.slice/docker.service/sys/fs/cgroup/systemd/system.slice/docker.service/usr/lib/systemd/system/docker.service [root@youx-pub registry] # vim / usr/lib/systemd/system/docker.service
Then perform the following:
# because the docker.service file that can be used for systemctl startup has changed, the following configuration has to be performed. Then perform the restart work of docker systemctl daemon-reloadsystemctl restart docker
If you still report the following error:
[root@youx-pub registry] # docker push 192.168.18.162:5000/nginx:1.2the push refers to a repository [192.168.18.162:5000/nginx] get https://192.168.18.162:5000/v1/_ping: http: server gave http response to https client [root@youx-pub registry] #
The solution is:
Create a daemon.json under / etc/docker, which reads:
{"insecure-registries": ["192.168.18.162 insecure-registries 5000"]}
Then restart the docker container:
[root@youx-pub volumes] # systemctl restart docker
5. After the upload is completed, we can check whether there is an image in the mount directory:
[root@xxx-pub docker-registry] # pwd/home/docker-registry [root@xxx-pub docker-registry] # ls / registry/docker
6. View the local image:
[root@xxx-pub docker-registry] # curl http://192.168.18.162:5000/v2/_catalog{"repositories":["xxx-centos7.5.1804","xxx-centos7.5.1804-v1.0"]}[root@xxx-pub docker-registry] #
7. When we see that there are two images, we need to obtain his tag information for download:
[root@xxx-pub docker-registry] # curl http://192.168.18.162:5000/v2/xxx-centos7.5.1804/tags/list{"name":"xxx-centos7.5.1804","tags":["1.0"]}[root@xxx-pub docker-registry] #
8. Then we download the image directly (to another computer):
[root@bigdata2 ~] # docker pull 192.168.18.162:5000/youx-centos7.5.1804:1.0using default tag: latesttrying to pull repository 192.168.18.162/youx-centos7.5.1804. Get https://192.168.18.162/v1/_ping: dial tcp 192.168.18.162 getsockopt: no route to host [root@bigdata2] #
If the above situation occurs, the solution is:
Compile:
[root@youx-pub volumes] # vim / etc/containers/registries.conf this file. The old one is the editor: / etc/sysconfig/docker.
Then restart docker
[root@youx-pub volumes] # systemctl restart docker
And then I found that I could pull.
# Note that the address here is: warehouse address: warehouse port number / repository:tag [root@bigdata2 ~] # docker pull 192.168.18.162:5000/youx-centos7.5.1804:1.0
If it doesn't work, you need to modify / etc/docker/daemon.json as follows:
[root@bigdata2 docker] # cat daemon.json {"insecure-registries": ["192.168.18.162 5000"]}
2. Upload the image from another machine to the docker image repository:
[root@bigdata2 ~] # docker tag centos7-jdk8-nginx:1.0 192.168.18.162:5000/centos7-jdk8-nginx:1.0 [root@bigdata2 ~] # docker imagesrepository tag image id created size192.168.18.162:5000/centos7-jdk8-nginx 1.0 bcacd65e2a2e 2 minutes ago 2.18 gb [root@bigdata2 ~] # docker push 192.168.18.162:5000/centos7-jdk8 -nginx:1.0the push refers to a repository [192.168.18.162:5000/centos7-jdk8-nginx] f018e9c38a66: pushed 2a47dcd341ef: pushed c5dea3bc729a: pushed bcc97fbfc9e1: pushed 1.0: digest: sha256:d907ff2f8eb590209700c01ce85c78d0bc778a4238539d747e4667d68cb52102 size: 1163 [root@bigdata2 ~] #
Then enter the location of the docker image repository:
[root@youx-pub registry] # curl http://192.168.18.162:5000/v2/_catalog{"repositories":["centos7-jdk8-nginx","nginx"]}[root@youx-pub registry] # curl http://192.168.18.162:5000/v2/centos7-jdk8-nginx/tags/list{"name":"centos7-jdk8-nginx","tags":["1.0"]}[root@youx-pub registry] #
Third, how to delete the local image? normally, the deletion function is not provided, so a third-party plug-in is used to delete it.
Location on the plug-in github:
1. Download resources
[root@master registry] # curl https://raw.githubusercontent.com/burnettk/delete-docker-registry-image/master/delete_docker_registry_image.py | sudo tee / usr/local/bin/delete_docker_registry_image > / dev/nullsudo chmod axix / usr/local/bin/delete_docker_registry_image
2. Set relevant link variables:
Find registry_data_dir Command: [root@youx-pub registry] # find /-name registry [root@youx-pub registry] # find /-name registry/var/lib/docker/overlay2/d72320cd67b42f7ae66342cc6dedab7abe5e89106de8c4919ec8c5a6e5940b09/diff/var/lib/ucf/registry/var/lib/docker/overlay2/92211417089f7be8239def550e1e89ce3f0e50ac57f2c36ba723ca312ea06ae3/diff/bin/registry/var/lib/docker/overlay2/c1716aea0b380eb94ead9aa02552769acd4c3dac8e6dab735997f1709ce79a33/diff/etc/docker/registry/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/diff/var/lib/registry/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/bin/ Registry/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/etc/docker/registry/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/var/lib/registry/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry/opt/data/registry/ register [root @ youx-pub registry] # post [root@youx-pub repositories] # pwd/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry/v2/ repositories [root @ youx-pub repositories] # lscentos7-jdk8-nginx nginx [ Root@youx-pub repositories] # so set the location of the image repository to: [root@master registry] # export registry_data_dir=/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry/v2
The address is our mount address:
Take a look at the relevant labels:
[root@youx-pub registry] # curl http://192.168.18.162:5000/v2/_catalog{"repositories":["youx-centos7.5.1804","youx-centos7.5.1804-v1.0"]}[root@youx-pub registry] # curl http://192.168.18.162:5000/v2/youx-centos7.5.1804-v1.0/tags/list{"name":"youx-centos7.5.1804-v1.0", "tags": ["latest"]} [root@youx-pub registry] #
We can delete it directly after that:
[root@master registry] # delete_docker_registry_image-- image youx-centos7.5.1804-v1.0:latest
Let's take a look at how many images there are in the local warehouse:
This is the end of [root@master registry] # curl http://192.168.18.162:5000/v2/_catalog{"repositories":["youx-centos7.5.1804"]}"Docker how to manage and delete images in the local repository. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.