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:latest
06a972de6218b1f1c3bf9b53eb9068dc66d147d14e18a89ab51db13e339d3dc9
Parameter 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:lastest
This is the source image and the image file that was just pulled;registry server:5000/nginx:kurisu
This 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!

Docker and virtual machines have their own advantages and disadvantages, and the choice should be based on specific needs. 1.Docker is lightweight and fast, suitable for microservices and CI/CD, fast startup and low resource utilization. 2. Virtual machines provide high isolation and multi-operating system support, but they consume a lot of resources and slow startup.

The core concept of Docker architecture is containers and mirrors: 1. Mirrors are the blueprint of containers, including applications and their dependencies. 2. Containers are running instances of images and are created based on images. 3. The mirror consists of multiple read-only layers, and the writable layer is added when the container is running. 4. Implement resource isolation and management through Linux namespace and control groups.

Docker simplifies the construction, deployment and operation of applications through containerization technology. 1) Docker is an open source platform that uses container technology to package applications and their dependencies to ensure cross-environment consistency. 2) Mirrors and containers are the core of Docker. The mirror is the executable package of the application and the container is the running instance of the image. 3) Basic usage of Docker is like running an Nginx server, and advanced usage is like using DockerCompose to manage multi-container applications. 4) Common errors include image download failure and container startup failure, and debugging skills include viewing logs and checking ports. 5) Performance optimization and best practices include mirror optimization, resource management and security improvement.

The steps to deploy containerized applications using Kubernetes and Docker include: 1. Build a Docker image, define the application image using Dockerfile and push it to DockerHub. 2. Create Deployment and Service in Kubernetes to manage and expose applications. 3. Use HorizontalPodAutoscaler to achieve dynamic scaling. 4. Debug common problems through kubectl command. 5. Optimize performance, define resource limitations and requests, and manage configurations using Helm.

Docker is an open source platform for developing, packaging and running applications, and through containerization technology, solving the consistency of applications in different environments. 1. Build the image: Define the application environment and dependencies through the Dockerfile and build it using the dockerbuild command. 2. Run the container: Use the dockerrun command to start the container from the mirror. 3. Manage containers: manage container life cycle through dockerps, dockerstop, dockerrm and other commands.

How to build portable applications with Docker and Linux? First, use Dockerfile to containerize the application, and then manage and deploy the container in a Linux environment. 1) Write a Dockerfile and package the application and its dependencies into a mirror. 2) Build and run containers on Linux using dockerbuild and dockerrun commands. 3) Manage multi-container applications through DockerCompose and define service dependencies. 4) Optimize the image size and resource configuration, enhance security, and improve application performance and portability.

Docker and Kubernetes improve application deployment and management efficiency through container orchestration. 1.Docker builds images through Dockerfile and runs containers to ensure application consistency. 2. Kubernetes manages containers through Pod, Deployment and Service to achieve automated deployment and expansion.

Docker and Kubernetes are leaders in containerization and orchestration. Docker focuses on container lifecycle management and is suitable for small projects; Kubernetes is good at container orchestration and is suitable for large-scale production environments. The combination of the two can improve development and deployment efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor
