Docker deploy a private warehouse (registry & Harbor)

Warehouse (Repository) is a centralized place to store the image.
The concept is a confusing registration server (registry). Warehouse management server is actually registered a specific server, you can have multiple warehouses on each server, and each warehouse following a multiple mirror. In this respect, the warehouse can be considered a specific project or directory. For example, the address of the warehouse docker.sina.com.cn/centos:centos7 it, docekr.sian.com.cn is a registered server address, centos is the repository name, centos7 a warehouse tag (label).

Docker Hub official repository
currently docker official maintains a public warehouse, Docker Hub, which already includes more than 1,500 of the mirror. Most of the demand, you can download the image directly in Docker Hub be achieved.

Deploying a private warehouse:

1, to deploy a private warehouse mirrored by the official registry:

Project environment:
two hosts (centos7): docker01: 172.16.1.30
docker02: 172.16.1.40 **

docker01:
(. 1) running a container based mirroring registry:
[root@sqm-docker01 ~]# docker run -d --name registry --restart=always -p 5000:5000 -v /data/registry:/var/lib/registry registry:latest

参数说明:
#registry服务默认监听的是5000端口
-v = --volume 数据卷,进行一个挂载:宿主机:容器内

(2) private warehouse named Mirror:
## Without naming a private warehouse, the default is to go public warehouses (docker hub), it is necessary to name mirrors.
Private warehouse image naming convention : host ip address: port number / xxxx (name needs to be changed)
to nignx mirror, for example, nginx download mirror:
[root@sqm-docker01 ~]# docker pull nginx

[root@sqm-docker01 ~]# docker tag  nginx:latest 172.16.1.30:5000/nginx:latest

Note: When you mirror in: after naming (nginx latest), also named after the image name as a label, because id numbers are the same.
If and when the source image (nginx: latest) to delete, named after the mirror will still exist, because the deletion of a label.

(3) modify the docker main configuration file:
[root@sqm-docker01 ~]# vim /usr/lib/systemd/system/docker.service

Local Warehouse designated ip address and port number:
Docker deploy a private warehouse (registry & Harbor)

Reload process and restart the docker services:

[root@sqm-docker01 ~]# systemctl daemon-reload
[root@sqm-docker01 ~]# systemctl restart docker

(4) the local mirror push into the private warehouse:
[root@sqm-docker01 ~]# docker push 172.16.1.30:5000/nginx:latest
Docker deploy a private warehouse (registry & Harbor)

// Check private warehouse in the mirror:

[root@sqm-docker01 ~]# curl 172.16.1.30:5000/v2/_catalog
{"repositories":["nginx"]}

// Check warehouse mirror Tags:

[root@sqm-docker01 ~]#  curl 172.16.1.30:5000/v2/nginx/tags/list
{"name":"nginx","tags":["latest"]}

docker02:
connecting docker01, pulling docker01 warehouse mirror from:
(1) modify the configuration files docker:
[root@sqm-docker02 ~]# vim /usr/lib/systemd/system/docker.service
Docker deploy a private warehouse (registry & Harbor)

Restart docker services:

[root@sqm-docker02 ~]# systemctl daemon-reload
[root@sqm-docker02 ~]# systemctl restart docker

(2) from a private repository pulls the mirror:

[root@sqm-docker02 ~]# docker pull 172.16.1.30:5000/nginx #使用pull命令进行拉取

Docker deploy a private warehouse (registry & Harbor)

(3) deploying nginx service:

[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

Docker deploy a private warehouse (registry & Harbor)

Access nginx page:
Docker deploy a private warehouse (registry & Harbor)

2, deployment Harbor (Hubble) Private Warehouse:

registry official of a private warehouse, while the harbor is a private warehouse of third parties.

(1) download compose:
Installation depends:
[root@sqm-docker01 ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
for download from github official website:
the URL of: https://github.com/docker/compose/releases
Docker deploy a private warehouse (registry & Harbor)
Docker deploy a private warehouse (registry & Harbor)

[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 compose Version:

[root@sqm-docker01 ~]# docker-compose -version
docker-compose version 1.24.0, build 0aa59064

(2) downloading the installation package and decompress harbor:

[root@sqm-docker01 ~]# tar zxf harbor-offline-installer-v1.7.4.tgz -C /usr/local/
[root@sqm-docker01 ~]# cd /usr/local/harbor/

Docker deploy a private warehouse (registry & Harbor)

Written harbor configuration file:
[root@sqm-docker01 harbor]# vim harbor.cfg
Docker deploy a private warehouse (registry & Harbor)
execute the script:
[root @ SQM-docker01 harbor] # ./install.sh
Docker deploy a private warehouse (registry & Harbor)

Enter the site: user admin, password: Harbor12345 (in the harbor can view the configuration file)
the URL of: http://172.16.1.30
[root@sqm-docker01 harbor]# vim harbor.cfg

Docker deploy a private warehouse (registry & Harbor)

Docker deploy a private warehouse (registry & Harbor)
Login screen is as follows:
Docker deploy a private warehouse (registry & Harbor)

(3) we create a new item on the page:
Docker deploy a private warehouse (registry & Harbor)
Docker deploy a private warehouse (registry & Harbor)
Docker deploy a private warehouse (registry & Harbor)

##修改docker配置文件:
[root@sqm-docker01 ~]# vim /usr/lib/systemd/system/docker.service
Docker deploy a private warehouse (registry & Harbor)

// reload docker:

[root@sqm-docker01 ~]# systemctl daemon-reload
[root@sqm-docker01 ~]# systemctl restart docker

// restart compose:
Note: Because just been restarted docker service, so we will need to restart all containers.

[root@sqm-docker01 harbor]# docker ps -a -q | xargs docker start

[root@sqm-docker01 harbor]# docker-compose stop

Docker deploy a private warehouse (registry & Harbor)
[root@sqm-docker01 harbor]# docker-compose start
Docker deploy a private warehouse (registry & Harbor)

(4) at the local terminal connected to harbor:
[root@sqm-docker01 harbor]# docker login -u admin -p Harbor12345 172.16.1.30:80
Docker deploy a private warehouse (registry & Harbor)

(5) will need to upload to the mirror harbor private warehouses are push:
# nginx for example, a local mirror command and push into the warehouse:
[root@sqm-docker01 harbor]# docker tag nginx:latest 172.16.1.30:80/sunqiuming/nginx:latest

[root@sqm-docker01 harbor]# docker push 172.16.1.30:80/sunqiuming/nginx:latest #push到刚才在网页上创建的项目
Docker deploy a private warehouse (registry & Harbor)

After a successful push, we see on the page:
Docker deploy a private warehouse (registry & Harbor)
Docker deploy a private warehouse (registry & Harbor)

docker02 connected Harbor:
(. 1) in order to enter the configuration file is no longer docker02 modifications, copy the configuration file on the docker docker01 to docker02:
# Free secret landing:
[root@sqm-docker01 ~]# ssh-keygen
Docker deploy a private warehouse (registry & Harbor)
[root@sqm-docker01 ~]# ssh-copy-id 172.16.1.40

[root@sqm-docker01 ~]# scp /usr/lib/systemd/system/docker.service [email protected]:/usr/lib/systemd/system/docker.service

重启docker服务:
[root@sqm-docker02 ~]# systemctl daemon-reload
[root@sqm-docker02 ~]# systemctl restart docker

(2) connected to a private harbor warehouse:
Docker deploy a private warehouse (registry & Harbor)

(3) from the harbor private warehouse pulls the mirror:
[root@sqm-docker02 ~]# docker pull 172.16.1.30:80/sunqiuming/nginx # points is pulling just uploaded image warehouse.
Docker deploy a private warehouse (registry & Harbor)
(4) in the final image, running nginx-based services and test page:
[root@sqm-docker02 ~]# docker run -d --name nginx -p 80:80 172.16.1.30:80/sunqiuming/nginx:latest
Docker deploy a private warehouse (registry & Harbor)

Private warehouse deployment is complete. . . . . . .

-------- end of this article so far, thanks for reading --------

Guess you like

Origin blog.51cto.com/13972012/2446357