日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

私有仓库建立

發布時間:2024/1/8 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 私有仓库建立 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

docker pull registry

1、以下是顯示下載完成信息

在這里插入代碼片`[root@docker root5]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE [root@docker root5]# docker pull registry Using default tag: latest latest: Pulling from library/registry df9b9388f04a: Pull complete 52dc419b0ee2: Pull complete b6846b9db566: Pull complete b0a23bbf973d: Pull complete c50f110701a7: Pull complete Digest: sha256:dc3cdf6d35677b54288fe9f04c34f59e85463ea7510c2a9703195b63187a7487 Status: Downloaded newer image for registry:latest docker.io/library/registry:latest `

2、在docker 引擎終端設置

這里要先做一個鏡像加速

[root@docker docker]# tee /etc/docker/daemon.json <<-'EOF' > { > "registry-mirrors": ["https://jqqwsp8f.mirror.aliyuncs.com"] > } > EOF {"registry-mirrors": ["https://jqqwsp8f.mirror.aliyuncs.com"] } [root@docker docker]# systemctl daemon-reload [root@docker docker]# systemctl restart docker [root@docker docker]# ls daemon.json key.json [root@docker docker]# vim daemon.json [root@docker docker]# systemctl daemon-reload [root@docker docker]# systemctl restart docker

vim /etc/docker/daemon.json
{
“insecure-registries”: [“192.168.10.41:5000”], //添加
“registry-mirrors”: [“https://05vz3np5.mirror.aliyuncs.com”]
}

systemctl restart docker.service

docker create -it registry /bin/bash

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f7497fcc8c2 registry “/entrypoint.sh /b…” 59 seconds ago Exited (2) 20 seconds ago musing_turing

[root@docker docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry latest 2e200967d166 5 weeks ago 24.2MB [root@docker docker]# docker create -it registry /bin/bash 9702b3ec209750cc93db305c521e3e81b6b1a974b7b69fb8ec3c327baadbc0d0 [root@docker docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9702b3ec2097 registry "/entrypoint.sh /bin…" 10 seconds ago Created angry_chebyshev

3、是異常狀態

docker start 6f7497fcc8c2

//宿主機的/data/registry自動創建掛載容器中的/tmp/registry
docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry

[root@docker docker]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry 822b4a132d27ffc62ffc38d7d01e1b04008198cf88107d853545435c2136e5d6 [root@docker docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 822b4a132d27 registry "/entrypoint.sh /etc…" 8 seconds ago Up 7 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp jolly_engelbart 9702b3ec2097 registry "/entrypoint.sh /bin…" 4 minutes ago Created angry_chebyshev

//更改標記為192.168.10.41:5000/nginx
docker tag nginx:latest 192.168.10.41:5000/nginx

//上傳
docker push 192.168.10.41:5000/nginx

[root@docker nginx_1]# docker tag nginx:1 192.168.10.41:5000/nginx:452 [root@docker nginx_1]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.10.41:5000/nginx 452 f9c2bacc8f4e 8 minutes ago 452MB nginx 1 f9c2bacc8f4e 8 minutes ago 452MB <none> <none> 9e17f7e2878d 16 minutes ago 308MB registry latest 2e200967d166 5 weeks ago 24.2MB centos 7 eeb6ee3f44bd 7 months ago 204MB [root@docker nginx_1]# docker push 192.168.10.41:5000/nginx:452 The push refers to repository [192.168.10.41:5000/nginx] f7bb05718032: Pushed d7a1c6f32b5d: Pushed ef188e401bb1: Pushed 022048f7bc0f: Pushed aaeca7b02c7a: Pushed 741d7cdc7a1a: Pushed 174f56854903: Pushed 452: digest: sha256:9fdd30e1be465c857684238fc72716b6792e6654a9146db2c189056ea94b1fea size: 1788 [root@docker nginx_1]# curl -XGET http://192.168.10.41:5000/v2/_catalog {"repositories":["nginx"]}

4、獲取私有倉庫列表

怎么獲取registry的鏡像倉庫中的鏡像信息
curl -XGET http://192.168.10.41:5000/v2/_catalog

//顯示上傳成功
{“repositories”:[“nginx”]}

5、測試私有倉庫下載

docker pull 192.168.10.41:5000/nginx

Using default tag: latest
latest: Pulling from nginx
000eee12ec04: Pull complete
eb22865337de: Pull complete
bee5d581ef8b: Pull complete
Digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a
Status: Downloaded newer image for 192.168.10.41:5000/nginx:latest
192.168.10.41:5000/nginx:latest

二部署 Harbor 服務

Harbor 被部署為多個 Docker 容器,因此可以部署在任何支持 Docker 的 Linux 發行版 上。(registry 為其核心組件)
Harbor比registry相比好處是:harbor 支持多種功能、圖形化界面管理、多用戶權限、角色管理機制、安全機制
服務端主機需要安裝 Python、Docker 和 Docker Compose。(web環境支持的是PY語言,故需要安裝Python)

1.下載 Harbor 安裝程序

wget http:// harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz

tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/

2. 配置 Harbor 參數文件

vim /usr/local/harbor/harbor.cfg
hostname = 192.168.10.41

[root@docker harbor]# vim harbor.cfg 1 ## Configuration file of Harbor2 3 #The IP address or hostname to access admin UI and registry se rvice.4 #DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.5 hostname = 192.168.1041

關于 Harbor.cfg 配置文件中有兩類參數:所需參數和可選參數

(1)所需參數 這些參數需要在配置文件 Harbor.cfg 中設置


如果用戶更新它們并運行 install.sh腳本重新安裝 Harbor,
參數將生效。具體參數如下:

hostname:用于訪問用戶界面和 register 服務。它應該是目標機器的 IP 地址或完全限 定的域名(FQDN)
例如 192.168.226.130 或 hub.kgc.cn。不要使用 localhost 或 127.0.0.1 為主機名。

ui_url_protocol:(http 或 https,默認為 http)用于訪問 UI 和令牌/通知服務的協議。如果公證處于啟用狀態,則此參數必須為 https。(身份驗證時會向Mysql數據庫進行比對,然后授予令牌)

max_job_workers:鏡像復制作業線程。

db_password:用于db_auth 的MySQL數據庫root 用戶的密碼。

customize_crt:該屬性可設置為打開或關閉,默認打開。打開此屬性時,準備腳本創建私鑰和根證書,用于生成/驗證注冊表令牌。
當由外部來源提供密鑰和根證書時,將此屬性設置為 off。

ssl_cert:SSL 證書的路徑,僅當協議設置為 https 時才應用。

ssl_cert_key:SSL 密鑰的路徑,僅當協議設置為 https 時才應用。

secretkey_path:用于在復制策略中加密或解密遠程 register 密碼的密鑰路徑。

(2)可選參數

這些參數對于更新是可選的,即用戶可以將其保留為默認值,并在啟動 Harbor 后在 Web UI 上進行更新。
如果進入 Harbor.cfg,只會在第一次啟動 Harbor 時生效,隨后對這些參數的更新,Harbor.cfg 將被忽略。

注意:如果選擇通過UI設置這些參數,請確保在啟動Harbour后立即執行此操作。具體來說,必須在注冊或在 Harbor 中創建任何新用戶之前設置所需的
auth_mode。當系統中有用戶時(除了默認的 admin 用戶),auth_mode 不能被修改。具體參數如下:

Email:Harbor需要該參數才能向用戶發送“密碼重置”電子郵件,并且只有在需要該功能時才需要。
請注意,在默認情況下SSL連接時沒有啟用。如果SMTP服務器需要SSL,但不支持STARTTLS,那么應該通過設置啟用SSL email_ssl = TRUE。

harbour_admin_password:管理員的初始密碼,只在Harbour第一次啟動時生效。之后,此設置將被忽略,并且應 UI中設置管理員的密碼。
請注意,默認的用戶名/密碼是 admin/Harbor12345。

auth_mode:使用的認證類型,默認情況下,它是 db_auth,即憑據存儲在數據庫中。對于LDAP身份驗證(以文件形式驗證),請將其設置為 ldap_auth。

self_registration:啟用/禁用用戶注冊功能。禁用時,新用戶只能由 Admin 用戶創建,只有管理員用戶可以在 Harbour中創建新用戶。
注意:當 auth_mode 設置為 ldap_auth 時,自注冊功能將始終處于禁用狀態,并且該標志被忽略。

Token_expiration:由令牌服務創建的令牌的到期時間(分鐘),默認為 30 分鐘。

project_creation_restriction:用于控制哪些用戶有權創建項目的標志。默認情況下, 每個人都可以創建一個項目。
如果將其值設置為“adminonly”,那么只有 admin 可以創建項目。

verify_remote_cert:打開或關閉,默認打開。此標志決定了當Harbor與遠程 register 實例通信時是否驗證 SSL/TLS 證書。
將此屬性設置為 off 將繞過 SSL/TLS 驗證,這在遠程實例具有自簽名或不可信證書時經常使用。

另外,默認情況下,Harbor 將鏡像存儲在本地文件系統上。在生產環境中,可以考慮使用其他存儲后端而不是本地文件系統,
如 S3、Openstack Swif、Ceph 等。但需要更新 common/templates/registry/config.yml 文件。

3. 啟動 Harbor

sh /usr/local/harbor/install.sh

#####下面這是查看harbor.v1.2.2.tar.gz里面的內容(不用做這一步操作)

4. 查看 Harbor 啟動鏡像

//查看鏡像
docker images

//查看容器

docker ps -a

cd /usr/local/harbor/
docker-compose ps


如果一切都正常,應該可以打開瀏覽器訪問 http://192.168.10.41 的管理頁面,默認 的管理員用戶名和密碼是 admin/Harbor12345。


//添加項目并且填寫項目名稱


此時可使用 Docker 命令在本地通過 127.0.0.1 來登錄和推送鏡像。默認情況下,
Register 服務器在端口 80 上偵聽.

//登錄
docker login -u admin -p Harbor12345 http://127.0.0.1

//下載鏡像進行測試
docker pull cirros

//鏡像打標簽
docker tag cirros 127.0.0.1/myproject-kgc/cirros:v1

//上傳鏡像到Harbor
docker push 127.0.0.1/myproject-kgc/cirros:v1

以上操作都是在 Harbor 服務器本地操作。如果其他客戶端上傳鏡像到 Harbor,就會報
如下錯誤。出現這問題的原因 Docker Registry 交互默認使用的是 HTTPS,但是搭建私有鏡
像默認使用的是 HTTP 服務,所以與私有鏡像交互時出現以下錯誤。

[root@client ~]# docker login -u admin -p Harbor12345 http://192.168.10.41
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.10.41/v2/: EOF

//解決:
[root@client ~]# vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.10.41 --containerd=/run/containerd/containerd.sock

[root@client ~]# systemctl daemon-reload
[root@client ~]# systemctl restart docker
[root@client ~]# docker login -u admin -p Harbor12345 http://192.168.10.41
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@client ~]# docker pull cirros
Using default tag: latest
latest: Pulling from library/cirros
3d6427f49fe3: Pull complete
1915bfe8159b: Pull complete
d0ec9ef25b96: Pull complete
Digest: sha256:8654d33ecbcdc8fd65c80325c3ec3b1bc938dfad9f20d1a2e3cf21e521ab70e6
Status: Downloaded newer image for cirros:latest
docker.io/library/cirros:latest

[root@docker yum.repos.d]# docker pull cirros Using default tag: latest latest: Pulling from library/cirros d0b405be7a32: Pull complete bd054094a037: Pull complete c6a00de1ec8a: Pull complete Digest: sha256:7b3e8db2c7501cdbf4b670335bbea911e30a21d502b4b0c179f6efc7912281b2 Status: Downloaded newer image for cirros:latest docker.io/library/cirros:latest [root@docker yum.repos.d]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE cirros latest f9cae1daf5f6 14 months ago 12.6MB

[root@client ~]# docker tag cirros 192.168.10.41/myproject/cirros:v2

[root@client ~]# docker push 192.168.10.41/myproject/cirros:v2
The push refers to repository [192.168.10.41/myproject/cirros]
abbd6d6ac643: Layer already exists
75b99987219d: Layer already exists
0cc237193a30: Layer already exists
v2: digest: sha256:96137d51e0e46006243fa2403723eb47f67818802d1175b5cde7eaa7f19446bd size: 943

5.維護管理Harbor

可以使用 docker-compose 來管理 Harbor。一些有用的命令如下所示,必須在與
docker-compose.yml 相同的目錄中運行。

修改 Harbor.cfg 配置文件
要更改 Harbour 的配置文件時,請先停止現有的 Harbour 實例并更新 Harbor.cfg;然
后運行 prepare 腳本來填充配置;最后重新創建并啟動 Harbour 的實例。

docker-compose down -v
Stopping nginx … done
Stopping harbor-jobservice … done
Stopping harbor-ui … done
Stopping harbor-adminserver … done
Stopping harbor-db … done
Stopping registry … done
Stopping harbor-log … done
Removing nginx … done
Removing harbor-jobservice … done
Removing harbor-ui … done
Removing harbor-adminserver … done
Removing harbor-db … done
Removing registry … done
Removing harbor-log … done
Removing network harbor_harbor

vim harbor.cfg

./prepare
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/app.conf
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/nginx.conf
loaded secret from file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/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/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.

//報錯:
docker-compose up -d
Creating network “harbor_harbor” with the default driver
ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-25094fc09b3c -j RETURN: iptables: No chain/target/match by that name.
(exit status 1))
//解決:關閉防火墻后,docker需要重啟
systemctl restart docker
docker-compose up -d
Creating network “harbor_harbor” with the default driver
Creating harbor-log … done
Creating harbor-db … done
Creating harbor-adminserver … done
Creating registry … done
Creating harbor-ui … done
Creating harbor-jobservice … done
Creating nginx … done

6.創建 Harbor 用戶

7.創建項目開發人員




//在客戶端上操作
[root@client ~]# docker rmi 192.168.10.418/myproject/cirros:v2
Untagged: 192.168.10.41/myproject/cirros:v2
Untagged: 192.168.10.41/myproject/cirros@sha256:96137d51e0e46006243fa2403723eb47f67818802d1175b5cde7eaa7f19446bd
//注銷登錄
[root@client ~]# docker logout 192.168.1041
Removing login credentials for 192.168.10.41

[root@client ~]# docker login 192.168.10.41
Username: pdada
Password: //填寫Harbor1234
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@client ~]# docker pull 192.168.10.418/myproject/cirros:v1
v1: Pulling from myproject-kgc/cirros
Digest: sha256:96137d51e0e46006243fa2403723eb47f67818802d1175b5cde7eaa7f19446bd
Status: Downloaded newer image for 192.168.10.41/myproject-kgc/cirros:v1
192.168.195.128/myproject-kgc/cirros:v1
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.195.128/myproject-kgc/cirros v1 bc94bceaae77 11 months ago 10.3MB
cirros latest bc94bceaae77 11 months ago 10.3MB

移除 Harbor 服務容器同時保留鏡像數據/數據庫
//在Harbor服務器上操作
docker-compose down -v
Stopping nginx … done
Stopping harbor-jobservice … done
Stopping harbor-ui … done
Stopping registry … done
Stopping harbor-db … done
Stopping harbor-adminserver … done
Stopping harbor-log … done
Removing nginx … done
Removing harbor-jobservice … done
Removing harbor-ui … done
Removing registry … done
Removing harbor-db … done
Removing harbor-adminserver … done
Removing harbor-log … done
Removing network harbor_harbor
如需重新部署,需要移除 Harbor 服務容器全部數據
持久數據,如鏡像,數據庫等在宿主機的/data/目錄下,日志在宿主機的
/var/log/Harbor/目錄下。
rm -rf /data/database/
rm -rf /data/registry/

總結

以上是生活随笔為你收集整理的私有仓库建立的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。