Deploy Harbor service, push and pull Docker images

1. Install Harbor

1. Software download

Software official website: https://github.com/goharbor/harbor/releases

The version I downloaded is1.10.6

2. First transfer the compressed package to the linux system

3. Use the command to decompress the compressed package

tar -zxvf harbor-offline-installer-v1.10.6.tgz

4. Enter the decompressed harbor directory and modify harbor.yml

hostname 192.168.1.100 # 修改主机名为当前系统的IP地址
# 下面两项看情况,没有端口冲突的话用默认的就行了
port: 5000 # 由于我80端口开了其他应用,防止有冲突,就换成了5000

You need to comment out all the sub-configurations under https, as shown in the figure below

Habor configuration file modification

Otherwise, the following error will be reported. The specific meaning is that you need to upload your certificate for https encryption service to make it more secure, but you have not uploaded it and modified the default certificate path, so an error occurred. We won't use it here for now.

https certificate issue

5. After modification, start the install.sh script in the harbor directory, execute the installation program, and the program will automatically complete the installation process

./install.sh

If the installation process is interrupted by other errors, you can refer to this blog:

[https://blog.csdn.net/muzizongheng/article/details/105286453](https://blog.csdn.net/muzizongheng/article/details/105286453#8. If you encounter an error: ERROR%3Aroot%3AError %3A The protocol is https but attribute ssl_cert is not set. The reason is that the port and certificate path of https are configured by default in harbor.yml.)

If the installation is successful, the following information will be printed:

Prompt for successful harbor installation

5. Then you can visit the home page of harbor with a browser

The default account password can be found in harbor.yml

Check the harbor initial password in the configuration file

Username is admin, password is Harbor12345

Log in successfully and enter the home page

2. Test push and pull docker image to Harbor server

1. First Harborcreate a new test project on the server

Log in to the Harbor homepage with a browser, create a new project, and fill in the project name. Take the project name as commonsan example. There is no limit to the storage quantity and capacity. The default is -1, and click OK.

Create a new project in the harbor console

You can see that there is an additional private project in the project list in the list commons, click on the project name,

View new projects

Enter the project operation interface and click the mirror warehouse

harbor project details

At the end there is a template for pushing the image, which can be copied for reference

The docker command provided by harbor to push the image

2. daemon.jsonAdd Harborthe address in

In order to better test the effect of the effect push, I restarted another virtual machine here, pre-installed dockeranddocker-compose

Modify /etc/docker/daemon.jsonthe file, add Harborthe address, so that dockerit can be found, the content is as follows:

{
    
    
  "registry-mirrors": ["https://43h8ayp0.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.1.100:5000"]
}

Restart dockerand verify that the configuration takes effect

systemctl restart docker  //重启docker
docker info

If you can see the content just configured, it will take effect

Check whether the docker private server harbor address is added successfully

3. Prepare a test image

Based on the official tomcatproduction of a mirror image with my own characteristics candytomcat, it will be pushed to Harborthe server for later testing

Build the image Dockerfilecontent as follows:

FROM tomcat
# 让tomcat的首页显示“Hello Harbor”字样
RUN echo "Hello Harbor" > /usr/local/tomcat/webapps/ROOT/index.jsp

build tomcatimage

docker build -t candytomcat .

Run the image you just built

docker run -p 8888:8080 candytomcat -d

The test image runs successfully, and the expected value can also be printed out in the browser

Make a mirror that can be accessed normally

Downloading images of other clients from harbor can run normally

Refer to the instruction just now in the server to mark the Harborcurrently built imagecandytomcat

docker tag candytomcat:latest 192.168.1.100:5000/commons/candytomcat:latest

View Dockermirror list

docker images

You can see that there is one more Harbormirror that conforms to the server naming format, so the mirror for testing is done

View mirror creation status

4. Test Harborto push candytomcatthe image to China

Since the project just created commonsis private, user login is required before uploading, here use the command to log in directly

docker login 192.168.1.100:5000 -u admin -p Harbor12345

192.168.1.100:5000/commons/candytomcat:latestUpload the image to the Harbor server

docker push 192.168.1.100:5000/commons/candytomcat:latest

As shown in the picture uploaded successfully

Push the created image to harbor for storage

HarborYou can also see the information of this image on the server

Check whether the upload is successful in the harbor console

5. Test Harbordownloading candytomcatimages from the service

In order to better test the effect of pulling the image, switch to another virtual machine

First of all, modify /etc/docker/daemon.jsonthe file first, add Harborthe address, the content is as follows:

{
    
    
  "registry-mirrors": ["https://43h8ayp0.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.1.100:5000"]
}

User login before pulling the image

docker login 192.168.1.100:5000 -u admin -p Harbor12345

pull 192.168.1.100:5000/commons/candytomcat:latestmirror

docker pull 192.168.1.100:5000/commons/candytomcat:latest

pull success

Pull the docker image uploaded by other clients just now

Guess you like

Origin blog.csdn.net/qq_38505969/article/details/114306771