Deploy Harbor service, push and pull Docker images
- 1. Install Harbor
-
- 1. Software download
- 2. First transfer the compressed package to the linux system
- 3. Use the command to decompress the compressed package
- 4. Enter the decompressed harbor directory and modify harbor.yml
- 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
- 5. Then you can visit the home page of harbor with a browser
- 2. Test push and pull docker image to Harbor server
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
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.
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:
5. Then you can visit the home page of harbor with a browser
The default account password can be found in harbor.yml
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 Harbor
create 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 commons
an example. There is no limit to the storage quantity and capacity. The default is -1, and click OK.
You can see that there is an additional private project in the project list in the list commons
, click on the project name,
Enter the project operation interface and click the mirror warehouse
At the end there is a template for pushing the image, which can be copied for reference
2. daemon.json
Add Harbor
the address in
In order to better test the effect of the effect push, I restarted another virtual machine here, pre-installed docker
anddocker-compose
Modify /etc/docker/daemon.json
the file, add Harbor
the address, so that docker
it can be found, the content is as follows:
{
"registry-mirrors": ["https://43h8ayp0.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.1.100:5000"]
}
Restart docker
and verify that the configuration takes effect
systemctl restart docker //重启docker
docker info
If you can see the content just configured, it will take effect
3. Prepare a test image
Based on the official tomcat
production of a mirror image with my own characteristics candytomcat
, it will be pushed to Harbor
the server for later testing
Build the image Dockerfile
content as follows:
FROM tomcat
# 让tomcat的首页显示“Hello Harbor”字样
RUN echo "Hello Harbor" > /usr/local/tomcat/webapps/ROOT/index.jsp
build tomcat
image
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
Refer to the instruction just now in the server to mark the Harbor
currently built imagecandytomcat
docker tag candytomcat:latest 192.168.1.100:5000/commons/candytomcat:latest
View Docker
mirror list
docker images
You can see that there is one more Harbor
mirror that conforms to the server naming format, so the mirror for testing is done
4. Test Harbor
to push candytomcat
the image to China
Since the project just created commons
is 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:latest
Upload the image to the Harbor server
docker push 192.168.1.100:5000/commons/candytomcat:latest
As shown in the picture uploaded successfully
Harbor
You can also see the information of this image on the server
5. Test Harbor
downloading candytomcat
images 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.json
the file first, add Harbor
the 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:latest
mirror
docker pull 192.168.1.100:5000/commons/candytomcat:latest
pull success