In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "Docker how to deploy private warehouses". In daily operation, I believe many people have doubts about how Docker deploys private warehouses. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "Docker how to deploy private warehouses"! Next, please follow the small series to learn together!
A repository is a centralized repository of images.
A confusing concept is registry. In fact, the registration server is the specific server that manages the repository. There can be multiple repositories on each server, and there are multiple mirrors under each repository. In this respect, a repository can be thought of as a concrete project or catalog. For example, for the repository address docker.sina.com.cn/centos:centos7, docker.sian.com.cn is the registry server address, centos is the repository name, and centos7 is the tag of the repository.
Docker Hub official repository
Docker officially maintains a public repository, Docker Hub, which already contains more than 1500 images. Most requirements can be met by downloading images directly from Docker Hub.
Deploying a private repository: 1. Deploying a private repository via an official registry mirror:
Project environment:
Two hosts (centos7): docker01: 172.16.1.30
docker02:172.16.1.40**
docker01:
(1) Run a container based on registry mirroring:
[root@sqm-docker01 ~]# docker run -d --name registry --restart=always -p 5000:5000 -v /data/registry:/var/lib/registry registry:latest
Parameter description: #registry service defaults to listening on port 5000-v = --volume data volume, and performs a mount: host: inside the container
(2) Named private repository mirror:
##If you don't name a private repository, the default is a public repository (docker hub), so you need to name the mirror.
Naming rules for private repository images: host IP address: port number/xxxx(name to be changed)
Take nignx image as an example, download nginx image:
[root@sqm-docker01 ~]# docker pull nginx
[root@sqm-docker01 ~]# docker tag nginx:latest 172.16.1.30:5000/nginx:latest
Note: When you name a source image (nginx:latest), the named image name is also considered a label because the id number is the same.
If the source image (nginx:latest) is deleted, the named image will still exist because it is a label that is deleted.
(3) Modify docker master configuration file:
[root@sqm-docker01 ~]# vim /usr/lib/systemd/system/docker.service
Specify IP address + port number of local repository:
Reload the process and restart the docker service:
[root@sqm-docker01 ~]# systemctl daemon-reload[root@sqm-docker01 ~]# systemctl restart docker
(4) Push the local image to the private repository:
[root@sqm-docker01 ~]# docker push 172.16.1.30:5000/nginx:latest
//View images in private repositories:
[root@sqm-docker01 ~]# curl 172.16.1.30:5000/v2/_catalog{"repositories":["nginx"]}
//View tags mirrored in the repository:
[root@sqm-docker01 ~]# curl 172.16.1.30:5000/v2/nginx/tags/list{"name":"nginx","tags":["latest"]}
//If I need to delete the image from my private repository, I tried to delete the image using the official third-party tool (deletedockerregistryimage), but it didn't delete the image from my repository. So I mount it in the local directory [/data/registry] when I run registry, and find the directory where the specified image is stored to delete it.
[root@sqm-docker01 ~]# cd /data/registry/docker/registry/v2/[root@sqm-docker01 v2]# lsblobs repositories[root@ sqm-docker01 v2]# cd repositories/[root@ sqm-docker 01 repositories]# lsnginx[root@sqm-docker 01 repositories]# rm -rf nginx/After deletion, check whether the image in the private repository still exists again: [root@sqm-docker01 ~]# curl http://172.16.1.30:5000/v2/_catalog{"repositories":[]}
You can see that the mirror in the repository has been successfully deleted.
docker02:
Connect docker01 and pull the image from the repository of docker01:(remember to upload the image to the private repository first)
(1) Modify docker configuration file:
[root@sqm-docker02 ~]# vim /usr/lib/systemd/system/docker.service
Restart docker service:
[root@sqm-docker02 ~]# systemctl daemon-reload[root@sqm-docker02 ~]# systemctl restart docker
(2) Pull images from private repositories:
[root@sqm-docker02 ~]# docker pull 172.16.1.30:5000/nginx
(3) Deployment of nginx services:
[root@sqm-docker02 ~]# mkdir html[root@sqm-docker02 ~]# echo "welcome to nginx web" > html/index.html
[root@sqm-docker02 ~]# docker run -itd --name nginx -p 80:80 -v /root/html:/usr/share/nginx/html 172.16.1.30:5000/nginx
Visit nginx page:
2, deploy Harbor private warehouse:
Registry is an official private repository, while harbour is a private repository of a third party.
(1) Download composition:
Installation dependencies:
[root@sqm-docker01 ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
Download from Github website:
URL:https://github.com/docker/compose/releases
[root@sqm-docker01 ~]# curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-uname -s-uname -m-o /usr/local/bin/docker-compose
[root@sqm-docker01 ~]# chmod +x /usr/local/bin/docker-compose
View the compose version:
[root@sqm-docker01 ~]# docker-compose -versiondocker-compose version 1.24.0, build 0aa59064
(2) Download the Harbor installation package and extract it:
[root@sqm-docker01 ~]# tar zxf harbor-offline-installer-v1.7.4.tgz -C /usr/local/[root@sqm-docker01 ~]# cd /usr/local/harbor/
Write the harbor configuration file:
[root@sqm-docker01 harbor]# vim harbor.cfg
Execute script:
[root@sqm-docker01 harbor]# ./ install.sh
Enter website: user admin, password: Harbor12345 (can be viewed in harbor configuration file)
URL:http://172.16.1.30
[root@sqm-docker01 harbor]# vim harbor.cfg
The login interface is as follows:
(3) We create a new project on the website:
##Modify docker configuration file:
[root@sqm-docker01 ~]# vim /usr/lib/systemd/system/docker.service
//reload docker:
[root@sqm-docker01 ~]# systemctl daemon-reload[root@sqm-docker01 ~]# systemctl restart docker
//restart compose:
Note: Since docker service has just been restarted, we need to restart all containers.
[root@sqm-docker01 harbor]# docker ps -a -q | xargs docker start
[root@sqm-docker01 harbor]# docker-compose stop
[root@sqm-docker01 harbor]# docker-compose start
(4)Connect harbor on local terminal:
[root@sqm-docker01 harbor]# docker login -u admin -p Harbor12345 172.16.1.30:80
(5) Push the image that needs to be uploaded to Harbor's private repository:
#For example, a local nginx mirror command and push to the repository:
[root@sqm-docker01 harbor]# docker tag nginx:latest 172.16.1.30:80/sunqiuming/nginx:latest
[root@sqm-docker01 harbour]# docker push 172.16.1.30:80/sunqiuming/nginx:latest #push to the item you just created on the web page
After push success, we check on the website:
docker02 Connect harbor:
(1) In order to stop entering the configuration file for modification in docker02, copy the docker configuration file on docker01 to docker02:
#Secret-free landing:
[root@sqm-docker01 ~]# ssh-keygen
[root@sqm-docker01 ~]# ssh-copy-id 172.16.1.40
[root@sqm-docker01 ~]# scp /usr/lib/systemd/system/docker.service root@172.16.1.40:/usr/lib/systemd/system/docker.service
Restart docker service:
[root@sqm-docker02 ~]# systemctl daemon-reload
[root@sqm-docker02 ~]# systemctl restart docker
(2) Connect harbor private repositories:
(3) Pull images from harbor private repositories:
[root@sqm-docker02 ~]# docker pull 172.16.1.30:80/sunqiuming/nginx #refers to pulling from the repository where the image was uploaded.
(4) Finally, based on this image, run the nginx service and test the web page:
[root@sqm-docker02 ~]# docker run -d --name nginx -p 80:80 172.16.1.30:80/sunqiuming/nginx:latest
At this point, the study of "Docker how to deploy private repositories" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.