Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build and use docker Private Warehouse

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to build and use docker private warehouse". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to build and use docker private warehouse.

Environmental planning

Two machines are required: the server in the docker private server warehouse and the ordinary machine that uses docker. The server,ip information of the ubuntu16 version of both machines is as follows:

Machine name ip function docker-registry192.168.119.148docker private warehouse server docker-app192.168.119.155 ordinary server running docker service

Prepare the machine

In this actual combat, the above two machines are two virtual machines created on vmware, and both have installed docker services. For the detailed creation and installation process, please refer to, remember to change the names of the two images to "docker-registry" and "docker-app" respectively in vmware, so as not to make a mistake later.

After the virtual machine starts, modify the / etc/hostname file first, change the hostname of the two machines to "docker-registry" and "docker-app" respectively, and then restart with the reboot command

Install a private warehouse

Log in to the docker-registry machine (securecrt is recommended)

Executing the following command starts a registry container that is used to provide services for private repositories:

Docker run-- name docker-registry-d-p 5000 registry

Execute the docker ps command to check the container, as shown below:

The container starts normally, and the external service is mapped to port 5000 of docker-registry through port 5000.

Execute the command curl-x get http://127.0.0.1:5000/v2/_catalog, and the response is as follows: it is a json object, where the value of repositories is an empty json array, indicating that there is no image in the repository:

{"repositories": []}

Ok, the private warehouse has been created and started, so let's try how to use it.

Support http protocol push

Normally, the application server pushes the image to the repository using https. Here, we use ordinary http to test the push through the command line, so we need to modify the startup parameters of docker to allow it to work with http protocol.

The machine that performs the push image is docker-app, so log in to this machine (securecrt is recommended)

Modify the / etc/default/docker file to add the following red box:

Then modify / lib/systemd/system/docker.service, the content in the following red box, the first behavior is added, the second behavior is modified:

Execute the following command to reload the configuration information and restart the docker service:

Systemctl daemon-reload;service docker restart

Push the image to the private warehouse

Next, we download an image in docker-app, and then push the image to a private repository.

Log in to the docker-app machine (securecrt is recommended)

Execute the command docker pull tomcat to download the latest version of tomcat image from hub.docker.com, as shown below:

After downloading, execute docker images to view the image information, as shown below:

As shown in the red box above, the id of this image is 3dcfe809147d, so we execute the following command to add a tag with private repository ip to the image, so that it can be successfully pushed to the private warehouse:

Docker tag 3dcfe809147d 192.168.119.148:5000/tomcat

Then execute docker images to check the image information, as shown in the following figure. A new image appears. Repository is 192.168.119.148:5000/tomcat:

Execute the following command to push:

Docker push 192.168.119.148:5000/tomcat

You can see that it is in progress, as shown in the following figure:

After the push is successful, execute curl-x get http://192.168.119.148:5000/v2/_catalog on docker-app and docker-registry, respectively, and view the image information of the private repository, you can see the following:

Use images of private repositories

On the docker-app machine, first execute the following command to delete the local image:

Docker rmi 192.168.119.148:5000/tomcat tomcat

Then execute the following command to create a container with the image on the private server, mapping port 8080:

Docker run-- name tomcat001-p 8080 idt 192.168.119.148:5000/tomcat

Download the image from private server if there is no local image, as shown below:

The ip of docker-app is 192.168.119.155, so open a browser on your current computer and type: 192.168.119.155 tomcat 8080, you can see the familiar welcome page of the following figure:

At this point, I believe you have a deeper understanding of "how to build and use docker private warehouse". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report