How to build a docker private warehouse
1. Background introduction
In Docker, when we execute the docker pull xxx command, we may be curious about where docker will search and What about downloading the image?
Related recommendations: docker tutorial
Question answer:
It actually goes from the registry.hub.docker.com address Search, this is the public warehouse provided by the Docker company. The above image is available to everyone and can be used. Therefore, we can also bring the warehouse address to pull the image, such as: docker pull registry.hub.docker.com/library/alpine, but be aware that the default name of the image downloaded in this way will be longer.
If we want to use Docker in the company, it is basically impossible for us to upload commercial projects to a public warehouse. So what can we do if we want to share it with multiple machines?
Because of this need, private warehouses come into play.
The so-called private warehouse is something similar to a public warehouse built locally (LAN). After it is built, we can submit the image to the private warehouse. In this way, we can use Docker to run our project images and avoid the risk of commercial projects being exposed.
Below we use the official registry image to build a private image warehouse. Of course, there are many other methods.
2. Environment
Prepare two servers with docker installed: Server machine (host name is registry): docker private warehouse server, running registry container; Test machine (host name is node): Ordinary docker server, download a test image nginx on this server, and then upload it to the registry server for testing;
3. Deployment (server operation)
-
Download image registry
# docker pull registryUsing default tag: latest latest: Pulling from library/registry 81033e7c1d6a: Pull complete b235084c2315: Pull complete c692f3a6894b: Pull complete ba2177f3a70e: Pull complete a8d793620947: Pull complete Digest: sha256:672d519d7fd7bbc7a448d17956ebeefe225d5eb27509d8dc5ce67ecb4a0bce54 Status: Downloaded newer image for registry:latest复制代码
-
View image
# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE registry latest f32a97de94e1 3 months ago 25.8 MB复制代码
-
Run registry container
# docker run -itd -v /data/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:latest06a972de6218b1f1c3bf9b53eb9068dc66d147d14e18a89ab51db13e339d3dc9Parameter description -itd: Open a pseudo terminal in the container for interactive operations and run it in the background; -v: Bind the host's /data/registry directory to the container's /var/lib/registry directory (this directory is the directory where image files are stored in the registry container) to achieve data persistence; -p: Mapping port; accessing the 5000 port of the host will access the service of the registry container; --restart=always: This is the restart strategy. If the container exits abnormally, the container will be automatically restarted; --name registry: Create a container named registry, you can name it whatever you want; registry:latest: This is the image that was just pulled;
-
Test all the images in the image warehouse
# curl http://127.0.0.1: 5000/v2/_catalog{"repositories":[]}
is now empty because it has just been run and there is no image content in it.
4. Test image warehouse (test side operation)
-
Modify the source and image warehouse
# vim /etc/docker/daemon.json{"registry-mirrors": [ "https://registry.docker-cn.com"] }# systemctl restart docker复制代码 -
Download nginx image
# docker pull nginx# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 719cd2e3ed04 2 weeks ago 109MB复制代码
-
Tag the image
# docker tag nginx:latest registry服务器:5000/nginx:kurisu复制代码
Format description: Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
nginx:lastestThis is the source image and the image file that was just pulled;registry server:5000/nginx:kurisuThis is the target Mirror is also the IP address and port of the registry's private mirror server;View the effect
# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry服务器:5000/nginx kurisu 719cd2e3ed04 2 weeks ago 109MB nginx latest 719cd2e3ed04 2 weeks ago 109MB复制代码
-
Upload to the mirror server
# docker push registry服务器:5000/nginxThe push refers to repository [registry服务器:5000/nginx] Get https://registry服务器:5000/v2/: http: server gave HTTP response to HTTPS client复制代码
This is an error, The https method is required to upload. We can modify daemon.json to solve the problem:
[root@node ~]# vim /etc/docker/daemon.json { "registry-mirrors": [ "https://registry.docker-cn.com"], "insecure-registries": [ "registry服务器:5000"] }复制代码Add the address of the private mirror server. Note that the writing format is json. There are strict writing requirements, and then restart the docker service:
# systemctl restart docker
Upload again:# docker push registry服务器:5000/nginxThe push refers to repository [registry服务器:5000/nginx] d7acf794921f: Pushed d9569ca04881: Pushed cf5b3c6798f7: Pushed kurisu: digest: sha256:079aa93463d2566b7a81cbdf856afc6d4d2a6f9100ca3bcbecf24ade92c9a7fe size: 948复制代码
-
Test download image
The upload test is no problem, let’s test it from the registry server Download the busybox image just uploaded, first delete the image on the node host:# docker rmi -f $(docker images -aq)Untagged: registry服务器:5000/nginx:kurisu Untagged: registry服务器:5000/nginx@sha256:079aa93463d2566b7a81cbdf856afc6d4d2a6f9100ca3bcbecf24ade92c9a7fe Untagged: nginx:latest Untagged: nginx@sha256:bdbf36b7f1f77ffe7bd2a32e59235dff6ecf131e3b6b5b96061c652f30685f3a Deleted: sha256:719cd2e3ed04781b11ed372ec8d712fac66d5b60a6fb6190bf76b7d18cb50105 Deleted: sha256:e9b6506fb887de50972aefd99d7c5eb56b1a8e757ed953cdfecb86b5359bcb22 Deleted: sha256:55d9d9692a9615a28d183a42bc3881a72a39393feba3664e669e7affb78daa76 Deleted: sha256:cf5b3c6798f77b1f78bf4e297b27cfa5b6caa982f04caeb5de7d13c255fd7a1e复制代码
Check that all the images on the node host have been deleted:
# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE复制代码
Then, download the nginx image from the registry server :
# docker pull registry服务器:5000/nginx:kurisukurisu: Pulling from nginxfc7181108d40: Pull complete c4277fc40ec2: Pull complete 780053e98559: Pull complete Digest: sha256:079aa93463d2566b7a81cbdf856afc6d4d2a6f9100ca3bcbecf24ade92c9a7fe Status: Downloaded newer image for registry服务器:5000/nginx:kurisu复制代码
View the image on the node host:
# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE registry服务器:5000/nginx kurisu 719cd2e3ed04 2 weeks ago 109MB复制代码
View the remote warehouse image
- List all images:
# curl http://registry服务器:5000/v2/_catalog{"repositories":["nginx"]}复制代码
- List the tags of the nginx image:
# curl http://registry服务器:5000/v2/nginx/tags/list{"name":"nginx","tags":["kurisu"]}复制代码The above is the detailed content of How to build a docker private warehouse. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
How to deploy a PyTorch app on Ubuntu
May 29, 2025 pm 11:18 PM
Deploying a PyTorch application on Ubuntu can be done by following the steps: 1. Install Python and pip First, make sure that Python and pip are already installed on your system. You can install them using the following command: sudoaptupdatesudoaptinstallpython3python3-pip2. Create a virtual environment (optional) To isolate your project environment, it is recommended to create a virtual environment: python3-mvenvmyenvsourcemyenv/bin/activatet
Performance Tuning of Jenkins Deployment on Debian
May 28, 2025 pm 04:51 PM
Deploying and tuning Jenkins on Debian is a process involving multiple steps, including installation, configuration, plug-in management, and performance optimization. Here is a detailed guide to help you achieve efficient Jenkins deployment. Installing Jenkins First, make sure your system has a Java environment installed. Jenkins requires a Java runtime environment (JRE) to run properly. sudoaptupdatesudoaptininstallopenjdk-11-jdk Verify that Java installation is successful: java-version Next, add J
How to implement automated deployment of Docker on Debian
May 28, 2025 pm 04:33 PM
Implementing Docker's automated deployment on Debian system can be done in a variety of ways. Here are the detailed steps guide: 1. Install Docker First, make sure your Debian system remains up to date: sudoaptupdatesudoaptupgrade-y Next, install the necessary software packages to support APT access to the repository via HTTPS: sudoaptinstallapt-transport-httpsca-certificatecurlsoftware-properties-common-y Import the official GPG key of Docker: curl-
What is Docker BuildKit, and how does it improve build performance?
Jun 19, 2025 am 12:20 AM
DockerBuildKit is a modern image building backend. It can improve construction efficiency and maintainability by 1) parallel processing of independent construction steps, 2) more advanced caching mechanisms (such as remote cache reuse), and 3) structured output improves construction efficiency and maintainability, significantly optimizing the speed and flexibility of Docker image building. Users only need to enable the DOCKER_BUILDKIT environment variable or use the buildx command to activate this function.
How does Docker work with Docker Desktop?
Jun 15, 2025 pm 12:54 PM
DockerworkswithDockerDesktopbyprovidingauser-friendlyinterfaceandenvironmenttomanagecontainers,images,andresourcesonlocalmachines.1.DockerDesktopbundlesDockerEngine,CLI,Compose,andothertoolsintoonepackage.2.Itusesvirtualization(likeWSL2onWindowsorHyp
How can you monitor the resource usage of a Docker container?
Jun 13, 2025 am 12:10 AM
To monitor Docker container resource usage, built-in commands, third-party tools, or system-level tools can be used. 1. Use dockerstats to monitor real-time: Run dockerstats to view CPU, memory, network and disk IO indicators, support filtering specific containers and recording regularly with watch commands. 2. Get container insights through cAdvisor: Deploy cAdvisor containers to obtain detailed performance data and view historical trends and visual information through WebUI. 3. In-depth analysis with system-level tools: use top/htop, iostat, iftop and other Linux tools to monitor resource consumption at the system level, and integrate Prometheu
What is Kubernetes, and how does it relate to Docker?
Jun 21, 2025 am 12:01 AM
Kubernetes is not a replacement for Docker, but the next step in managing large-scale containers. Docker is used to build and run containers, while Kubernetes is used to orchestrate these containers across multiple machines. Specifically: 1. Docker packages applications and Kubernetes manages its operations; 2. Kubernetes automatically deploys, expands and manages containerized applications; 3. It realizes container orchestration through components such as nodes, pods and control planes; 4. Kubernetes works in collaboration with Docker to automatically restart failed containers, expand on demand, load balancing and no downtime updates; 5. Applicable to application scenarios that require rapid expansion, running microservices, high availability and multi-environment deployment.
How does Docker differ from traditional virtualization?
Jul 08, 2025 am 12:03 AM
The main difference between Docker and traditional virtualization lies in the processing and resource usage of the operating system layer. 1. Docker containers share the host OS kernel, which is lighter, faster startup, and more resource efficiency; 2. Each instance of a traditional VM runs a full OS, occupying more space and resources; 3. The container usually starts in a few seconds, and the VM may take several minutes; 4. The container depends on namespace and cgroups to achieve isolation, while the VM obtains stronger isolation through hypervisor simulation hardware; 5. Docker has better portability, ensuring that applications run consistently in different environments, suitable for microservices and cloud environment deployment.



