本文收錄在容器技術學習系列文章總目錄html
(1)Repositorynginx
(2)Indexgit
(1)拉取鏡像github
docker pull <registry>[:<port>]/[<namespace>/]<name>:<tag>
(2)上傳鏡像web
docker push [OPTIONS] NAME[:TAG]
例:docker pull quay.io/coreos/flannel:v0.10.0-amd64redis
博主前面的文章已經詳細介紹過,從第三方的registry 上傳拉取鏡像了;這篇就是詳細講解若是搭建私有registry ,並在私有registry上傳拉取鏡像了。sql
docker提供的開源Registry,可是很簡單,只能做爲存儲鏡像的倉庫,沒有額外的功能;如管理頁面等docker
兩種方案安裝,我採用的是方案2數據庫
[root@docker2 ~]# yum info docker-distribution 已加載插件:fastestmirror Loading mirror speeds from cached hostfile 可安裝的軟件包 名稱 :docker-distribution 架構 :x86_64 版本 :2.6.2 發佈 :2.git48294d9.el7 大小 :3.5 M 源 :extras/7/x86_64 簡介 : Docker toolset to pack, ship, store, and deliver content 網址 :https://github.com/docker/distribution 協議 : ASL 2.0 描述 : Docker toolset to pack, ship, store, and deliver content [root@docker2 ~]# yum -y install docker-distribution
(1)拉取鏡像json
[root@docker2 ~]# docker pull registry:2.6.2 2.6.2: Pulling from library/registry d6a5679aa3cf: Pull complete ad0eac849f8f: Pull complete 2261ba058a15: Pull complete f296fda86f10: Pull complete bcd4a541795b: Pull complete Digest: sha256:5a156ff125e5a12ac7fdec2b90b7e2ae5120fa249cf62248337b6d04abc574c8 Status: Downloaded newer image for registry:2.6.2
(2)啓動registry 容器
[root@docker2 ~]# docker run --name registry -p 5000:5000 -v /data/registry:/var/lib/registry -d registry:2.6.2 a43f802e737eba89879a4dc02562b38e0042db981f9bdb91782b453f0bac4119 [root@docker2 ~]# docker port registry 5000/tcp -> 0.0.0.0:5000 [root@docker2 ~]# ss -nutlp |grep 5000 tcp LISTEN 0 128 :::5000 :::* users:(("docker-proxy",pid=4901,fd=4)) [root@docker2 ~]# docker inspect -f {{."Mounts"}} registry [{bind /data/registry /var/lib/registry true rprivate}]
注:
(1)先將本地倉庫打上合適的標籤
[root@docker1 ~]# docker tag busybox:latest 192.168.10.102:5000/busybox:v0.1 [root@docker1 ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.10.102:5000/busybox v0.1 758ec7f3a1ee 13 days ago 1.15 MB busybox latest 758ec7f3a1ee 13 days ago 1.15 MB
(2)嘗試刪除鏡像
[root@docker1 ~]# docker push 192.168.10.102:5000/busybox:v0.1 The push refers to a repository [192.168.10.102:5000/busybox] Get https://192.168.10.102:5000/v1/_ping: http: server gave HTTP response to HTTPS client
上傳鏡像失敗;緣由:docker 上傳下載默認只支持https協議,搭建的私有倉庫是http協議。
(3)修改重啓docker服務
[root@docker1 ~]# vim /etc/docker/daemon.json { "registry-mirrors": ["https://registry.docker-cn.com"], "insecure-registries": ["192.168.10.102:5000"] } [root@docker1 ~]# systemctl restart docker
注:就是將私有倉庫認證爲安全倉庫:"insecure-registries": [""]
(4)再次上傳鏡像,成功
[root@docker1 ~]# docker push 192.168.10.102:5000/busybox:v0.1 The push refers to a repository [192.168.10.102:5000/busybox] 23bc2b70b201: Pushed v0.1: digest: sha256:cbcde3595079b1f7a6b046e96e7547fe786d5c2c8eba678bc260161bc01b8dbe size: 527
(5)在私有倉庫的服務器上驗證
[root@docker2 ~]# ls /data/registry/docker/registry/v2/ blobs repositories
(6)從私有倉庫拉取鏡像,先刪除再拉取
[root@docker1 ~]# docker rmi 192.168.10.102:5000/busybox:v0.1 Untagged: 192.168.10.102:5000/busybox:v0.1 Untagged: 192.168.10.102:5000/busybox@sha256:cbcde3595079b1f7a6b046e96e7547fe786d5c2c8eba678bc260161bc01b8dbe [root@docker1 ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest 758ec7f3a1ee 2 weeks ago 1.15 MB [root@docker1 ~]# docker pull 192.168.10.102:5000/busybox:v0.1 v0.1: Pulling from busybox Digest: sha256:cbcde3595079b1f7a6b046e96e7547fe786d5c2c8eba678bc260161bc01b8dbe Status: Downloaded newer image for 192.168.10.102:5000/busybox:v0.1 [root@docker1 ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.10.102:5000/busybox v0.1 758ec7f3a1ee 2 weeks ago 1.15 MB
(1)參數介紹
① 配置參數位於文件harbor.cfg中。
② 在harbor.cfg中有兩類參數,必需參數和可選參數。
③ 注意:若是您選擇經過Portal設置這些參數,請務必在Harbour啓動後當即執行此操做。特別是,您必須在Harbour中註冊或建立任何新用戶以前設置所需的auth_mode。當系統中有用戶時(除默認管理員用戶外), 沒法更改auth_mode。
④ 請注意,至少須要更改hostname屬性。
(2)必需參數
(3)可選參數
(4)配置存儲後端(可選)
默認狀況下,Harbor將圖像存儲在本地文件系統中。在生產環境中,您能夠考慮使用其餘存儲後端而不是本地文件系統,如S3,OpenStack Swift,Ceph等。這些參數是註冊表的配置。
例如,若是使用Openstack Swift做爲存儲後端,則參數可能以下所示:
registry_storage_provider_name = swift registry_storage_provider_config = 「 username:admin,password:ADMIN_PASS,authurl:http:// keystone_addr:35357 / v3 / aut
注意:有關注冊表存儲後端的詳細信息,請參閱「 註冊表配置參考」。
資源 | 容量 | 描述 |
---|---|---|
CPU | 最小2 CPU | 4 CPU是首選 |
內存 | 最小4GB | 8GB是首選 |
磁盤 | 最小40GB | 160GB是首選 |
軟件 | 版 | 描述 |
---|---|---|
Python | 2.7或更高版本 | 請注意,您可能必須在Linux發行版(Gentoo,Arch)上安裝Python,默認狀況下不安裝Python解釋器 |
Docker engine | 版本1.10或更高版本 | 有關安裝說明,請參閱:https://docs.docker.com/engine/installation/ |
Docker Compose | 版本1.6.0或更高版本 | 有關安裝說明,請參閱:https://docs.docker.com/compose/install/ |
Openssl | 最新的是首選 | 爲Harbor生成證書和密鑰 |
端口 | 協議 | 描述 |
---|---|---|
443 | HTTPS | Harbor門戶和核心API將接受此端口上的https協議請求 |
4443 | HTTPS | 只有在啓用「公證」時才須要鏈接到Dock的Docker Content Trust服務 |
80 | HTTP | Harbor端口和核心API將接受此端口上的http協議請求 |
博主也是太長時間沒有進行硬盤添加的操做了,熟悉一遍
(1)查詢添加的磁盤的名字
$ fdisk -l Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
(2)對磁盤進行分區
$ fdisk /dev/sdb Command (m for help): m Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Using default response p Partition number (1-4, default 1): First sector (2048-104857599, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): Using default value 104857599 Partition 1 of type Linux and of size 50 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
(3)磁盤文件格式化
$ [root@centos7-1 ~]# mkfs.ext3 /dev/sdb1
(4)掛載磁盤
$ vim /etc/fstab 設爲開機自動掛載 /dev/sdb1 /data ext3 defaults 0 0 $ mount -a 掛載磁盤
(5)驗證
[root@centos7-1 ~]# df -h /data Filesystem Size Used Avail Use% Mounted on /dev/sdb1 50G 52M 47G 1% /data
方案1:直接yum安裝
[root@docker2 ~]# yum -y install docker-compose
方案2:在GitHub上選擇本身須要的版本下載安裝https://github.com/docker/compose/releases
$ curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose $ chmod +x /usr/local/bin/docker-compose $ docker-compose version docker-compose version 1.23.2, build 1110ad01 docker-py version: 3.6.0 CPython version: 3.6.7 OpenSSL version: OpenSSL 1.1.0f 25 May 2017
資源能夠下載的很慢,我已經將1.7.1版本放入個人網盤了,須要的私聊
[root@docker2 ~]# wget https://storage.googleapis.com/harbor-releases/release-1.7.0/harbor-offline-installer-v1.7.1.tgz [root@docker2 ~]# tar -C /data/ -xvf harbor-offline-installer-v1.7.1.tgz
(1)修改harbor.cfg 配置文件
[root@docker2 ~]# cd /data/harbor/ [root@docker2 harbor]# grep "^[^#]" harbor.cfg _version = 1.7.0 hostname = docker2 ui_url_protocol = http max_job_workers = 2 customize_crt = on ssl_cert = /data/cert/server.crt ssl_cert_key = /data/cert/server.key secretkey_path = /data admiral_url = NA log_rotate_count = 50 log_rotate_size = 200M http_proxy = https_proxy = no_proxy = 127.0.0.1,localhost,core,registry email_identity = email_server = smtp.mydomain.com email_server_port = 25 email_username = sample_admin@mydomain.com email_password = abc email_from = admin <sample_admin@mydomain.com> email_ssl = false email_insecure = false harbor_admin_password = Harbor12345 auth_mode = db_auth ldap_url = ldaps://ldap.mydomain.com ldap_basedn = ou=people,dc=mydomain,dc=com ldap_uid = uid ldap_scope = 2 ldap_timeout = 5 ldap_verify_cert = true ldap_group_basedn = ou=group,dc=mydomain,dc=com ldap_group_filter = objectclass=group ldap_group_gid = cn ldap_group_scope = 2 self_registration = on token_expiration = 30 project_creation_restriction = everyone db_host = postgresql db_password = along db_port = 5432 db_user = postgres redis_host = redis redis_port = 6379 redis_password = along redis_db_index = 1,2,3 clair_db_host = postgresql clair_db_password = along clair_db_port = 5432 clair_db_username = postgres clair_db = postgres clair_updaters_interval = 12 uaa_endpoint = uaa.mydomain.org uaa_clientid = id uaa_clientsecret = secret uaa_verify_cert = true uaa_ca_cert = /path/to/ca.pem registry_storage_provider_name = filesystem registry_storage_provider_config = registry_custom_ca_bundle =
主要修改了:
hostname:主機名
max_job_workers:最大cpu數,小於等於本身服務器的硬件
(2)定義docker-compose.yml 文件(可省略)
docker-compose.yml 文件是docker 編排時,對容器的一些操做:
① 端口
ports:
- 80:80
- 443:443
- 4443:4443
② 衆多存儲器路徑
如:volumes:
- /data/registry:/storage:z
在生產環境中,儘可能將容器的存儲卷定義在空間較爲充足的磁盤;
本身根據實際狀況進行修改;
[root@docker2 harbor]# ./install.sh [Step 0]: checking installation environment ... Note: docker version: 18.03.1 Note: docker-compose version: 1.23.2 [Step 1]: loading Harbor images ... Loaded image: goharbor/registry-photon:v2.6.2-v1.7.1 Loaded image: goharbor/harbor-migrator:v1.7.1 Loaded image: goharbor/harbor-adminserver:v1.7.1 Loaded image: goharbor/harbor-core:v1.7.1 Loaded image: goharbor/harbor-log:v1.7.1 Loaded image: goharbor/harbor-jobservice:v1.7.1 Loaded image: goharbor/notary-server-photon:v0.6.1-v1.7.1 Loaded image: goharbor/clair-photon:v2.0.7-v1.7.1 Loaded image: goharbor/harbor-portal:v1.7.1 Loaded image: goharbor/harbor-db:v1.7.1 Loaded image: goharbor/redis-photon:v1.7.1 Loaded image: goharbor/nginx-photon:v1.7.1 Loaded image: goharbor/harbor-registryctl:v1.7.1 Loaded image: goharbor/notary-signer-photon:v0.6.1-v1.7.1 Loaded image: goharbor/chartmuseum-photon:v0.7.1-v1.7.1 [Step 2]: preparing environment ... Generated and saved secret to file: /data/secretkey Generated configuration file: ./common/config/nginx/nginx.conf Generated configuration file: ./common/config/adminserver/env Generated configuration file: ./common/config/core/env Generated configuration file: ./common/config/registry/config.yml Generated configuration file: ./common/config/db/env Generated configuration file: ./common/config/jobservice/env Generated configuration file: ./common/config/jobservice/config.yml Generated configuration file: ./common/config/log/logrotate.conf Generated configuration file: ./common/config/registryctl/env Generated configuration file: ./common/config/core/app.conf Generated certificate, key file: ./common/config/core/private_key.pem, cert file: ./common/config/registry/root.crt The configuration files are ready, please use docker-compose to start the service. [Step 3]: checking existing instance of Harbor ... [Step 4]: starting Harbor ... Creating network "harbor_harbor" with the default driver Creating harbor-log ... done Creating registry ... done Creating harbor-db ... done Creating registryctl ... done Creating harbor-adminserver ... done Creating redis ... done Creating harbor-core ... done Creating harbor-portal ... done Creating harbor-jobservice ... done Creating nginx ... done ✔ ----Harbor has been installed and started successfully.---- Now you should be able to visit the admin portal at http://docker2. For more details, please visit https://github.com/goharbor/harbor .
(1)打開了一些端口
[root@docker2 harbor]# ss -nutlp |grep docker tcp LISTEN 0 128 127.0.0.1:1514 *:* users:(("docker-proxy",pid=1440,fd=4)) tcp LISTEN 0 128 :::80 :::* users:(("docker-proxy",pid=2204,fd=4)) tcp LISTEN 0 128 :::443 :::* users:(("docker-proxy",pid=2192,fd=4)) tcp LISTEN 0 128 :::4443 :::* users:(("docker-proxy",pid=2181,fd=4))
(2)harbor實際就是啓動了一些docker服務
[root@docker2 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES def22a8eeb9a goharbor/nginx-photon:v1.7.1 "nginx -g 'daemon of…" 2 hours ago Up 2 hours (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp nginx a410a38479fa goharbor/harbor-portal:v1.7.1 "nginx -g 'daemon of…" 2 hours ago Up 2 hours (healthy) 80/tcp harbor-portal e25f87eb80db goharbor/harbor-jobservice:v1.7.1 "/harbor/start.sh" 2 hours ago Up 2 hours harbor-jobservice 2be7211535a2 goharbor/harbor-core:v1.7.1 "/harbor/start.sh" 2 hours ago Up 2 hours (healthy) harbor-core 26681dde1dec goharbor/harbor-db:v1.7.1 "/entrypoint.sh post…" 2 hours ago Up 2 hours (healthy) 5432/tcp harbor-db 80f592176896 goharbor/harbor-registryctl:v1.7.1 "/harbor/start.sh" 2 hours ago Up 2 hours (healthy) registryctl def7f9892e46 goharbor/redis-photon:v1.7.1 "docker-entrypoint.s…" 2 hours ago Up 2 hours 6379/tcp redis 9af874368813 goharbor/registry-photon:v2.6.2-v1.7.1 "/entrypoint.sh /etc…" 2 hours ago Up 2 hours (healthy) 5000/tcp registry 0f7156ac62f7 goharbor/harbor-adminserver:v1.7.1 "/harbor/start.sh" 2 hours ago Up 2 hours (healthy) harbor-adminserver 3e45524ef1f0 goharbor/harbor-log:v1.7.1 "/bin/sh -c /usr/loc…" 2 hours ago Up 2 hours (healthy) 127.0.0.1:1514->10514/tcp harbor-log
(1)網頁登陸http://192.168.130.102
(2)登陸harbor 後一些簡單的操做
(3)用戶管理
注:密碼要有必定的複雜度
(4)郵件配置
(5)新建一個項目
(1)修改docker配置,添加harbor倉庫爲新人地址
[root@docker1 ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://registry.docker-cn.com"], "insecure-registries": ["192.168.10.102:5000"], "insecure-registries": ["docker2:80"] } [root@docker1 ~]# systemctl restart docker
(2)把要上傳的鏡像打上合適的標籤
[root@docker1 ~]# docker tag busybox:latest docker2:80/demo/busybox:v0.1 [root@docker1 ~]# docker tag nginx:1.14-alpine docker2:80/demo/nginx:v0.1 [root@docker1 ~]# docker tag nginx:1.14 docker2:80/demo/nginx:v0.2 [root@docker1 ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker2:80/demo/nginx v0.2 3f55d5bb33f3 11 days ago 109 MB docker2:80/demo/busybox v0.1 758ec7f3a1ee 2 weeks ago 1.15 MB docker2:80/demo/nginx v0.1 c5b6f731fbc0 2 weeks ago 17.7 MB
(3)登陸harbor倉庫
[root@docker1 ~]# docker login docker2:80 Username: admin Password: Login Succeeded
(4)上傳鏡像
[root@docker1 ~]# docker push docker2:80/demo/busybox:v0.1 The push refers to a repository [docker2:80/demo/busybox] 23bc2b70b201: Pushed v0.1: digest: sha256:cbcde3595079b1f7a6b046e96e7547fe786d5c2c8eba678bc260161bc01b8dbe size: 527 [root@docker1 ~]# docker push docker2:80/demo/nginx #若是不知道tag,會把這個鏡像的全部tag都上傳 The push refers to a repository [docker2:80/demo/nginx] 59b059d445c1: Layer already exists 0246bb21855f: Layer already exists 42acf078bf60: Layer already exists 7bff100f35cb: Layer already exists v0.1: digest: sha256:438d8080098025e9983f253af806c1d1aa6b48be2ef1913991dab506bb3d4f72 size: 1153 6959f2c2a244: Pushed 06eb7a5682d6: Pushed 7b4e562e58dc: Pushed v0.2: digest: sha256:1313a52e3fd1718b1c36822cefa0e51950654004dcf12b08affb3067e02c6d9c size: 948
(5)在harbor 上驗證上傳成功
(6)拉取harbor 中的鏡像
[root@docker1 ~]# docker rmi docker2:80/demo/busybox:v0.1 Untagged: docker2:80/demo/busybox:v0.1 Untagged: docker2:80/demo/busybox@sha256:cbcde3595079b1f7a6b046e96e7547fe786d5c2c8eba678bc260161bc01b8dbe [root@docker1 ~]# docker image ls docker2:80/demo/busybox:v0.1 REPOSITORY TAG IMAGE ID CREATED SIZE [root@docker1 ~]# docker pull docker2:80/demo/busybox:v0.1 v0.1: Pulling from demo/busybox Digest: sha256:cbcde3595079b1f7a6b046e96e7547fe786d5c2c8eba678bc260161bc01b8dbe Status: Downloaded newer image for docker2:80/demo/busybox:v0.1 [root@docker1 ~]# docker image ls docker2:80/demo/busybox:v0.1 REPOSITORY TAG IMAGE ID CREATED SIZE docker2:80/demo/busybox v0.1 758ec7f3a1ee 2 weeks ago 1.15 MB
(7)在harbor web頁面能夠進行不少實用的操做
如:給鏡像打標、複製鏡像、刪除鏡像等
在harbor 安裝路徑下,使用docker-compose 命令對harbor 進行控制
(1)暫停harbor服務
[root@docker2 harbor]# docker-compose pause Pausing harbor-log ... done Pausing harbor-adminserver ... done Pausing registry ... done Pausing redis ... done Pausing registryctl ... done Pausing harbor-db ... done Pausing harbor-core ... done Pausing harbor-jobservice ... done Pausing harbor-portal ... done Pausing nginx ... done
(2)關閉harbor服務
[root@docker2 harbor]# docker-compose stop Stopping nginx ... done Stopping harbor-portal ... done Stopping harbor-jobservice ... done Stopping harbor-core ... done Stopping harbor-db ... done Stopping registryctl ... done Stopping redis ... done Stopping registry ... done Stopping harbor-adminserver ... done Stopping harbor-log ... done [root@docker2 harbor]# ss -nutl Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp LISTEN 0 128 *:22 *:*
(3)開啓harbor服務
[root@docker2 harbor]# docker-compose start Starting log ... done Starting registry ... done Starting registryctl ... done Starting postgresql ... done Starting adminserver ... done Starting core ... done Starting portal ... done Starting redis ... done Starting jobservice ... done Starting proxy ... done