您好,登錄后才能下訂單哦!
Registry用于保存docker鏡像,包括鏡像的層次結(jié)構(gòu)和元數(shù)據(jù)。用戶(hù)可以自建Registry,也可使用官方的Docker Hub。
Docker Registry 分類(lèi):
使用前先要將服務(wù)部署到服務(wù)器上。
可以通過(guò)yum安裝:
yum install docker-registry
yum install docker-distribution
上面兩個(gè)命令都會(huì)安裝docker-distribution只要執(zhí)行一個(gè)就好了。
軟件包的信息:
[root@Docker ~]# yum info docker-distribution
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
可安裝的軟件包
名稱(chēng) :docker-distribution
架構(gòu) :x86_64
版本 :2.6.2
發(fā)布 :2.git48294d9.el7
大小 :3.5 M
源 :extras/7/x86_64
簡(jiǎn)介 : Docker toolset to pack, ship, store, and deliver content
網(wǎng)址 :https://github.com/docker/distribution
協(xié)議 : ASL 2.0
描述 : Docker toolset to pack, ship, store, and deliver content
[root@Docker ~]#
這個(gè)就不裝了,因?yàn)檫€可以將服務(wù)安裝在容器中運(yùn)行。
docker官方也提供了容器,基于容器提供Registry服務(wù)。
下載鏡像:
[root@Docker ~]# docker image pull registry
Using default tag: latest
latest: Pulling from library/registry
c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for registry:latest
[root@Docker ~]#
啟動(dòng)容器:
docker run -d -p 5000:5000 --restart always --name registry registry
配置文件
查看registry的配置文件:
[root@Docker ~]# docker container exec -it registry cat /etc/docker/registry/config.yml
version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
[root@Docker ~]#
這里是默認(rèn)的配置文件。配置文件是通過(guò)CMD命令指定的,默認(rèn)的dockerfile的CMD指令如下:
CMD ["/etc/docker/registry/config.yml"]
鏡像存放的位置
鏡像Dockerfile中有一條VOLUME指令,這個(gè)路徑就是容器是存放鏡像的路徑:
VOLUME ["/var/lib/registry"]
啟動(dòng)鏡像時(shí),可以使用-v參數(shù),指定宿主機(jī)的目錄。
上傳鏡像前,先要給鏡像打標(biāo):
[root@Docker ~]# docker push busybox loclhost:5000/busybox
這里要準(zhǔn)備將本地的busybox推送到服務(wù)器loclhost:5000。這里省略了倉(cāng)庫(kù)的用戶(hù)名,沒(méi)有用戶(hù)名就是一個(gè)頂層倉(cāng)庫(kù)。
推送:
[root@Docker ~]# docker push localhost:5000/busybox
The push refers to repository [localhost:5000/busybox]
0d315111b484: Pushed
latest: digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649 size: 527
[root@Docker ~]#
不往本機(jī)lo接口推,也就是服務(wù)器地址不使用localhost或127.0.0.1。而是向本機(jī)的網(wǎng)卡地址推。就像其他主機(jī)要向本機(jī)的registry推送一樣了。然后會(huì)產(chǎn)生如下的錯(cuò)誤:
[root@Docker ~]# docker push 192.168.24.170:5000/busybox
The push refers to repository [192.168.24.170:5000/busybox]
Get https://192.168.24.170:5000/v2/: http: server gave HTTP response to HTTPS client
[root@Docker ~]#
這里的問(wèn)題是,docker默認(rèn)是使用https協(xié)議工作的,而registry服務(wù)器的響應(yīng)是http協(xié)議。解決的辦法有兩個(gè)。
第一個(gè)方法是修改registry來(lái)適應(yīng)docker,registry服務(wù)器改為https協(xié)議
第二個(gè)方法是修改docker來(lái)使用registry,將registry服務(wù)器地址加入到docker的insecure-registries中去
配置insecure-registries
修改配置文件,然后重啟加載后就可以推送上去了:
[root@Docker ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn"],
"insecure-registries": ["192.168.24.170:5000"]
}
[root@Docker ~]# systemctl reload docker
[root@Docker ~]# docker push 192.168.24.170:5000/busybox
The push refers to repository [192.168.24.170:5000/busybox]
0d315111b484: Layer already exists
latest: digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649 size: 527
[root@Docker ~]#
指定Registry下載之前上傳的鏡像:
[root@Docker ~]# docker pull 192.168.24.170:5000/busybox
Using default tag: latest
latest: Pulling from busybox
ee153a04d683: Pull complete
Digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
Status: Downloaded newer image for 192.168.24.170:5000/busybox:latest
[root@Docker ~]#
Harbor是一個(gè)用于存儲(chǔ)和分發(fā)Docker鏡像的企業(yè)級(jí)Registry服務(wù)器。
基于角色的訪問(wèn)控制:用戶(hù)與Docker鏡像倉(cāng)庫(kù)通過(guò)“項(xiàng)目”進(jìn)行組織管理,一個(gè)用戶(hù)可以對(duì)多個(gè)鏡像倉(cāng)庫(kù)在同一命名空間(project)里有不同的權(quán)限。
鏡像復(fù)制:鏡像可以在多個(gè)Registry實(shí)例中復(fù)制(同步)。尤其適合于負(fù)載均衡,高可用,混合云和多云的場(chǎng)景。
圖形化用戶(hù)界面:用戶(hù)可以通過(guò)瀏覽器來(lái)瀏覽,檢索當(dāng)前Docker鏡像倉(cāng)庫(kù),管理項(xiàng)目和命名空間。
AD/LDAP 支持:Harbor可以集成企業(yè)內(nèi)部已有的AD/LDAP,用于鑒權(quán)認(rèn)證管理。
審計(jì)管理:所有針對(duì)鏡像倉(cāng)庫(kù)的操作都可以被記錄追溯,用于審計(jì)管理。
國(guó)際化:已擁有英文、中文、德文、日文和俄文的本地化版本。更多的語(yǔ)言將會(huì)添加進(jìn)來(lái)。
RESTful API:RESTful API 提供給管理員對(duì)于Harbor更多的操控, 使得與其它管理軟件集成變得更容易。
部署簡(jiǎn)單:提供在線和離線兩種安裝工具, 也可以安裝到vSphere平臺(tái)(OVA方式)虛擬設(shè)備。
github項(xiàng)目地址:
https://github.com/vmware/harbor
這是一個(gè)vmware的開(kāi)源項(xiàng)目,實(shí)際會(huì)跳轉(zhuǎn)到下面這個(gè)地址:
https://github.com/goharbor/harbor
下載 harbor
查看項(xiàng)目的README,F(xiàn)eatures的內(nèi)容上面提過(guò)了,這里主要看Install & Run部分的內(nèi)容。
首先是下載
Harbor release:
https://github.com/goharbor/harbor/releases
$ wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.2-rc1.tgz
安裝配置向?qū)?/strong>
Installation & Configuration Guide:
https://github.com/goharbor/harbor/blob/master/docs/installation_guide.md
硬件要求:
Resource | Capacity | Description |
---|---|---|
CPU | minimal 2 CPU | 4 CPU is preferred |
Mem | minimal 4GB | 8GB is preferred |
Disk | minimal 40GB | 160GB is preferred |
軟件要求:
Software | Version | Description |
---|---|---|
Docker engine | version 17.06.0-ce+ or higher | For installation instructions, please refer to: docker engine doc |
Docker Compose | version 1.18.0 or higher | For installation instructions, please refer to: docker compose doc |
Openssl | latest is preferred | Generate certificate and keys for Harbor |
安裝步驟:
下載完之后,先解壓:
[root@Harbor ~]# tar xvf harbor-offline-installer-v1.8.1.tar -C /opt
harbor/harbor.v1.8.1.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/harbor.yml
[root@Harbor ~]#
下載的文件在解壓后就不需要了。解壓后的文件在安裝完成后也都是不需要的。所以下載到哪里,解壓到哪里其實(shí)都不重要。建議可以解壓到 /opt 或 /usr/local 這兩個(gè)目錄里。
安裝包中的鏡像
解壓后的文件中,有一個(gè)文件harbor.v1.8.1.tar.gz。這個(gè)是被導(dǎo)出的docker鏡像。還記得docker save命令吧,可以打包導(dǎo)出多個(gè)鏡像并完成壓縮:
$ docker save myimg/httpd:v1 myimg/httpd:v2 | gzip > myimage_latest.tar.gz
這個(gè)文件應(yīng)該就是這么來(lái)的。之后的安裝過(guò)程中,則是會(huì)把這個(gè)文件里的所有鏡像做一次批量導(dǎo)入:
$ docker load -i myimage_latest.tar.gz
在安裝時(shí)執(zhí)行的install.sh腳本里有解壓并導(dǎo)入鏡像的語(yǔ)句:
if [ -f harbor*.tar.gz ]
then
h3 "[Step $item]: loading Harbor images ..."; let item+=1
docker load -i ./harbor*.tar.gz
fi
安裝的依賴(lài)和過(guò)程
Harbor的安裝,就是給當(dāng)前的主機(jī)安裝很多容器,并且把這些容器都啟動(dòng)起來(lái)。啟動(dòng)Harbor就是用docker-compose把這些容器的啟動(dòng)起來(lái),而關(guān)閉harbor也是通過(guò)docker-compose來(lái)把容器一次關(guān)閉。之所以需要借助docker-compose,因?yàn)閔arbor是由很多容器協(xié)同過(guò)程的,容器之間又依賴(lài)關(guān)系,這些都需要docker-compose這個(gè)單機(jī)編排工具來(lái)協(xié)調(diào)。
所以安裝harbor前,需要安裝好docker-compose,才能實(shí)現(xiàn)本地的容器的編排。需要安裝好docker,才能把本地的鏡像啟動(dòng)起來(lái)。鏡像就在下載解壓的文件中。并且還需要啟動(dòng)docker,這樣才能運(yùn)行容器。
準(zhǔn)備工作完成后,就是執(zhí)行harbor準(zhǔn)備的install.sh腳本,在本地加載好鏡像,通過(guò)docker-compose把這些鏡像依次啟動(dòng)起來(lái),并且運(yùn)行在本地的docker上。
修改harbor.yml配置文件,主機(jī)名一定看改掉,最好使用本機(jī)的域名,如果沒(méi)有域名那么就用本機(jī)的IP地址。沒(méi)改的話,會(huì)有如下的錯(cuò)誤提示:
[root@Harbor harbor]# ./install.sh
? Please set hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.yml bacause notary must run under https.
Please set --with-clair if needs enable Clair in Harbor
Please set --with-chartmuseum if needs enable Chartmuseum in Harbor
[root@Harbor harbor]#
檢查發(fā)現(xiàn)沒(méi)有安裝docker:
[root@Harbor harbor]# ./install.sh
[Step 0]: checking installation environment ...
? Need to install docker(17.06.0+) first and run this script again.
[root@Harbor harbor]#
檢查發(fā)現(xiàn)沒(méi)有安裝docker-compose:
[root@Harbor harbor]# ./install.sh
[Step 0]: checking installation environment ...
Note: docker version: 19.03.1
? Need to install docker-compose(1.18.0+) by yourself first and run this script again.
[root@Harbor harbor]#
檢查發(fā)現(xiàn)docker沒(méi)有啟動(dòng):
[root@Harbor harbor]# ./install.sh
[Step 0]: checking installation environment ...
Note: docker version: 19.03.1
Note: docker-compose version: 1.18.0
[Step 1]: loading Harbor images ...
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@Harbor harbor]#
Docker的單機(jī)編排工具。官方文檔:
https://docs.docker.com/compose/
為了簡(jiǎn)化harbor的安裝和部署,所以harbor做成了在容器中運(yùn)行的應(yīng)用。但是harbor的運(yùn)行還依賴(lài)很多其他的應(yīng)用,所以需要編排幾個(gè)容器來(lái)協(xié)同工作。所以harbor的部署和使用時(shí)需要借助Docker的單機(jī)編排工具Docker Compose。
安裝docker-compose,位于epel源中:
yum install docker-compose
Compose模板文件
模板文件是使用Compose的核心,設(shè)計(jì)的指令關(guān)鍵字也有很多,默認(rèn)的模板文件名稱(chēng)為docker-compose.yml,格式為YAML格式。
這個(gè)不是重點(diǎn),能安裝使用harbor就好了,不過(guò)還是簡(jiǎn)單了解一下。
要使用docker-compose就要寫(xiě)一個(gè)編排腳本,和dockerfile類(lèi)似,也是有很多指令。定義要啟動(dòng)的每一個(gè)容器,指明依賴(lài)關(guān)系,這樣被依賴(lài)的容器需要先啟動(dòng)。關(guān)閉容器的時(shí)候也要對(duì)稱(chēng),先把沒(méi)有被依賴(lài)的容器關(guān)閉掉。
順便就來(lái)看下harbor的docker-compose.yml文件:
[root@Harbor harbor]# cat docker-compose.yml
version: '2.3' # docker-compose的版本
services: # 定義一個(gè)服務(wù)
log: # 服務(wù)的名稱(chēng),服務(wù)是通過(guò)容器來(lái)提供的,具體就是下面的設(shè)置
image: goharbor/harbor-log:v1.8.1 # 指定容器的鏡像,也可以用build指令通過(guò)dockerfile創(chuàng)建
container_name: harbor-log # 生成的容器的名稱(chēng)
restart: always # 容器自動(dòng)重啟
dns_search: .
cap_drop:
- ALL
cap_add:
- CHOWN
- DAC_OVERRIDE
- SETGID
- SETUID
volumes: # 定義卷
- /var/log/harbor/:/var/log/docker/:z
- ./common/config/log/:/etc/logrotate.d/:z
ports:
- 127.0.0.1:1514:10514
networks: # 加入的網(wǎng)絡(luò)
- harbor
registry:
image: goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1
container_name: registry
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
volumes:
- /data/registry:/storage:z
- ./common/config/registry/:/etc/registry/:z
- type: bind
source: /data/secret/registry/root.crt
target: /etc/registry/root.crt
networks:
- harbor
dns_search: .
depends_on: # 依賴(lài)的容器名稱(chēng)
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "registry"
registryctl:
image: goharbor/harbor-registryctl:v1.8.1
container_name: registryctl
env_file:
- ./common/config/registryctl/env
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
volumes:
- /data/registry:/storage:z
- ./common/config/registry/:/etc/registry/:z
- type: bind
source: ./common/config/registryctl/config.yml
target: /etc/registryctl/config.yml
networks:
- harbor
dns_search: .
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "registryctl"
postgresql:
image: goharbor/harbor-db:v1.8.1
container_name: harbor-db
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- DAC_OVERRIDE
- SETGID
- SETUID
volumes:
- /data/database:/var/lib/postgresql/data:z
networks:
harbor:
dns_search: .
env_file:
- ./common/config/db/env
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "postgresql"
core:
image: goharbor/harbor-core:v1.8.1
container_name: harbor-core
env_file:
- ./common/config/core/env
restart: always
cap_drop:
- ALL
cap_add:
- SETGID
- SETUID
volumes:
- /data/ca_download/:/etc/core/ca/:z
- /data/psc/:/etc/core/token/:z
- /data/:/data/:z
- ./common/config/core/certificates/:/etc/core/certificates/:z
- type: bind
source: ./common/config/core/app.conf
target: /etc/core/app.conf
- type: bind
source: /data/secret/core/private_key.pem
target: /etc/core/private_key.pem
- type: bind
source: /data/secret/keys/secretkey
target: /etc/core/key
networks:
harbor:
dns_search: .
depends_on:
- log
- registry
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "core"
portal:
image: goharbor/harbor-portal:v1.8.1
container_name: harbor-portal
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
- NET_BIND_SERVICE
networks:
- harbor
dns_search: .
depends_on:
- log
- core
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "portal"
jobservice:
image: goharbor/harbor-jobservice:v1.8.1
container_name: harbor-jobservice
env_file:
- ./common/config/jobservice/env
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
volumes:
- /data/job_logs:/var/log/jobs:z
- type: bind
source: ./common/config/jobservice/config.yml
target: /etc/jobservice/config.yml
networks:
- harbor
dns_search: .
depends_on:
- redis
- core
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "jobservice"
redis:
image: goharbor/redis-photon:v1.8.1
container_name: redis
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
volumes:
- /data/redis:/var/lib/redis
networks:
harbor:
dns_search: .
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "redis"
proxy:
image: goharbor/nginx-photon:v1.8.1
container_name: nginx
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
- NET_BIND_SERVICE
volumes:
- ./common/config/nginx:/etc/nginx:z
networks:
- harbor
dns_search: .
ports:
- 80:80
depends_on:
- postgresql
- registry
- core
- portal
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"
networks:
harbor:
external: false
[root@Harbor harbor]#
安裝前,需要去修改一下harbor.yml這個(gè)文件的配置,至少要把主機(jī)名改掉,之前已經(jīng)說(shuō)過(guò)了。其他配置按需要修改,不改也能夠安裝了。
一切準(zhǔn)備就行,就可以安裝了:
[root@Harbor harbor]# ./install.sh
[Step 0]: checking installation environment ...
Note: docker version: 19.03.1
Note: docker-compose version: 1.18.0
[Step 1]: loading Harbor images ...
ba58b7bb3f17: Loading layer 33.32MB/33.32MB
......略過(guò)......
Loaded image: goharbor/clair-photon:v2.0.8-v1.8.1
[Step 2]: preparing environment ...
prepare base dir is set to /opt/harbor
Generated configuration file: /config/log/logrotate.conf
......略過(guò)......
Generated certificate, key file: /secret/core/private_key.pem, cert file: /secreCreating harbor-log ... done
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
Creating registry ... done
Creating harbor-core ... done
[Step 3]: starting Harbor ...
Creating harbor-portal ... done
Creating nginx ... done
Creating harbor-db ...
Creating redis ...
Creating registryctl ...
Creating registry ...
Creating harbor-core ...
Creating harbor-portal ...
Creating harbor-jobservice ...
Creating nginx ...
? ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://HarborStudy.
For more details, please visit https://github.com/goharbor/harbor .
[root@Harbor harbor]#
安裝成功,可以看看監(jiān)聽(tīng)的端口,安裝了哪些鏡像,啟動(dòng)了哪些容器:
$ ss -tnl
$ docker images
$ docker ps
默認(rèn)的密碼在harbor.yml有設(shè)置的:
harbor_admin_password: Harbor12345
用戶(hù)名是admin,密碼沒(méi)改的話就是默認(rèn)的,可以登錄進(jìn)去。
使用瀏覽器訪問(wèn)Web頁(yè)面,可以看到一些管理界面。
另外要上傳或下載鏡像,需要在命令行使用docker命令,在那之前也需要登錄Harbor,使用docker login命令來(lái)完成登錄:
[root@Harbor harbor]# docker login localhost
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@Harbor harbor]#
登錄成功之后,才能推送鏡像。
要想停止或啟動(dòng)harbor,需要通過(guò)docker-compose命令。
在操作之前,最好先切換目錄到要操作的docker-compose.yml所在的目錄,這樣docker-compose能夠自動(dòng)找到模板文件并進(jìn)行操作。
停止harbor:
[root@Harbor harbor]# cd /opt/harbor/
[root@Harbor harbor]# docker-compose stop
Stopping nginx ... done
Stopping harbor-portal ... done
Stopping harbor-jobservice ... done
Stopping harbor-core ... done
Stopping registryctl ... done
Stopping harbor-db ... done
Stopping registry ... done
Stopping redis ... done
Stopping harbor-log ... done
[root@Harbor harbor]#
然后再次啟動(dòng):
[root@Harbor harbor]# docker-compose start
Starting log ... done
Starting registry ... done
Starting registryctl ... done
Starting postgresql ... done
Starting core ... done
Starting portal ... done
Starting redis ... done
Starting jobservice ... done
Starting proxy ... done
[root@Harbor harbor]#
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。