容器化的環境下,公司內部使用的鏡像不可能直接放在 dockerhub 上,更不可能只放在某臺機器上,因此一個公司內部的私有的 docker 鏡像倉庫(registry)必須存在。java
目前來說,docker registry 的實現還蠻多,包括官方的 registry、harbor,以及 nexus 等。node
本文會講 nexus 和 harbor 的使用,爲何要使用兩個而不是其中一個呢?由於它們都有缺陷,二者合一用起來才完美。python
harbor 的優點很明顯,特別是能夠自建文件夾進行分組這點就很是好。其實說實話,做爲一個私有的鏡像倉庫,harbor 已經作得很好的了,惟一的缺點是它沒法幫你下載鏡像。linux
也可能並非缺點,只是定位不一樣,而在這一點上 nexus 就很好的作到了,可是 nexus 除了這點外,其餘好像沒什麼值得稱道的地方了。nginx
爲何須要 Registry 幫你下載鏡像呢?由於在 kubernetes 環境下,你確定有去公網拉鏡像的需求,不管是官方仍是非官方。你不可能由於這個而特意給你的全部 node 節點開通外網訪問吧,這樣風險太多且不可控。在我看來,整個 kubernetes 集羣都不能訪問外網。git
這時 nexus 就有了用武之地了,當你須要拉公網鏡像的時候,你只要向它發起請求,它若是本地沒有,就會自動去你配置的鏡像倉庫下載,下載完成以後先在本地緩存一份,而後發送給你。github
你甚至不用給 nexus 開通外網,只須要在一臺能夠訪問外網的機器上搭建一個代理服務就行,讓 nexus 經過代理去下載。那這方面的內容,我以前的文章中已經給出瞭解決方法,歡迎查看。web
好了,關於 nexus 和 harbor 對比的簡單說明就這麼多了。那麼本文的目標就是搭建 nexus 和 harbor,並使用免費可靠的 https 證書來開啓 https。docker
nexus 最初是給 java 用的,後來慢慢發展,能夠做爲衆多軟件的倉庫,好比 pipy、yum 等,在 3.0 版本中更是加入了 docker registry 的支持,所以咱們要使用的至少是 3.0 版。json
nexus 提供了 web 界面,默認監聽 8081 端口,咱們幾乎全部的操做均可以在 web 界面上完成。當 docker 鏈接 nexus 時,默認經過 https,可是這只是針對 docker 倉庫的端口(須要配置),而不是針對 web 界面。
也就是說,docker 並不會鏈接 web 界面所監聽的 8081 端口,所以咱們無需對 web 界面進行 https 配置。可是話又說回來,反正都要配 https 了,那將 web 界面進行 https 也只是順手的事。
說了這麼多,咱們正式開始搭建。nexus 版本從 3 開始才支持 docker registry,這點須要注意,咱們就直接下載最新版就行了。你能夠直接訪問官方文檔來全面瞭解它。
nexus 支持 docker 部署,咱們這裏就不用了,直接使用一臺 Linux(CentOS7)搞起。
首先須要安裝 jdk,官方說不支持 openjdk,只支持 oracle jdk。那麼直接去 oracle 官網下載最新版的 rpm 包,放到服務器上使用 rpm -ivh
進行安裝便可:
curl -v -j -k -L -H "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm >jdk-8u201-linux-x64.rpm
rpm -ivh jdk-8u201-linux-x64.rpm
複製代碼
下載 jdk 完成後會出現下面這樣信息,但這並非報錯。
* Connection #0 to host download.oracle.com left intact
複製代碼
接着下載並解壓 nexus:
cd /opt
wget http://download.sonatype.com/nexus/3/nexus-3.15.2-01-unix.tar.gz
tar xf nexus-3.15.2-01-unix.tar.gz
ln -s nexus-3.15.2-01/ nexus
複製代碼
當咱們使用 root 用戶啓動時,雖然也能成功啓動,可是它會拋出警告信息:
# cd nexus/bin
# ./nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Starting nexus
複製代碼
所以咱們須要建立一個普通用戶來啓動它:
# ./nexus stop
# groupadd -g 1111 nexus
# useradd -u 1111 -g 1111 nexus
# chown -R nexus. /opt/sonatype-work/
# su - nexus
$ /opt/nexus/bin/nexus start
複製代碼
能夠驗證下它是否啓動成功:
$ ss -tnl | grep 8081
LISTEN 0 50 *:8081 *:*
複製代碼
咱們能夠在 /opt/nexus/bin 下面看到一個 nexus.vmoptions 的配置文件,經過這個配置文件能夠直接 jvm 參數。
$ cat nexus.vmoptions
-Xms1200M
-Xmx1200M
-XX:MaxDirectMemorySize=2G
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
複製代碼
這裏的相對路徑是相對於 nexus 自己,而非 nexus/bin。咱們能夠看到它會自動在 nexus 目錄的父目錄下生成 sonatype-work 目錄,用來放配置文件、數據,還有日誌等,你能夠經過修改配置文件來改變它的位置。
前面使用 root 用戶啓動以後生成的這個目錄的權限是 root,再使用普通用戶啓動的話,普通用戶會由於沒有權限往裏面的日誌文件中寫數據而致使啓動失敗,因此只是上面要修改這個目錄權限的緣由。
此時你能夠直接使用瀏覽器訪問 http://ip:8081 來打開它的 web 界面了,以後咱們全部的操做都會在 web 界面上進行。在配置以前,咱們先將 https 配置上去。之因此使用 https,是由於 docker 訪問 registry 默認就是使用 https,若是使用 http 也行,可是會增長不少操做。
nexus 使用 https 的方式有兩種,一種是直接配置 nexus 使用 https,另外一種就是前面使用 nginx 配置 https,而後反向代理到後端的 nexus,其中客戶端和 nginx 之間使用 https,nginx 和 nexus 之間則使用 http。而無論是從易用性仍是實用性的角度,咱們都應該使用 nginx。
其實咱們要使用 https 的地方在於 docker 和 registry 之間,而非 nexus 的 web 界面。docker 和 registry 之間通訊會使用另外的端口,並且 pull 和 push 端口都不同,這個下面會講到。
可是既然都要配 https 了,咱們將 web 訪問也配上 https 也只是順手的事,反正證書都是使用同一個,並且使用 https 逼格更高。
OK,咱們先安裝 nginx。
# cat >/etc/yum.repos.d/nginx.repo <<'EOF'
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
EOF
# yum install -y nginx
複製代碼
若是說你的服務器不能訪問外網,能夠參考我前面寫的一篇文章,教你如何在可以上網的機器上搭建代理服務,讓其餘內網服務器經過它來上網。那若是說你連一臺可以上網的機器都沒有,那你也能夠經過上面的 nginx URL 將 rpm 包下載下來安裝便可,它沒有任何依賴。
要使用 https 首先得有證書,這方面能夠參考該系列的上一篇文章,很容易就可以獲取到安全可靠的 https 證書。那我這裏就使用文章中已經申請下來的 *.ntpstat.com
這個通配符證書,準備使用 registry.ntpstat.com 做爲 nexus 的域名。
那直接開始修改 nginx 配置文件。
# vim /etc/nginx/nginx.conf
# 替換 http 上下文的內容
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
proxy_send_timeout 120;
proxy_read_timeout 300;
proxy_buffering off;
keepalive_timeout 5 5;
tcp_nodelay on;
sendfile on;
#tcp_nopush on;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
# 添加 https 配置
# vim /etc/nginx/conf.d/ssl.conf
server {
listen *:443;
server_name registry.ntpstat.com;
# 容許大文件上傳
client_max_body_size 1G;
# 對大於 1G 文件的下載進行優化
#proxy_max_temp_file_size 2G;
ssl on;
ssl_certificate /etc/nginx/cert/fullchain.pem;
ssl_certificate_key /etc/nginx/cert/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8081/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https";
}
}
複製代碼
檢查配置文件沒有問題以後,就能夠啓動 nginx 了:
# nginx -t
# systemctl start nginx
複製代碼
接着在本地配置 hosts 文件,將 registry.ntpstat.com(換成你的域名)映射到服務器所在 ip,而後在瀏覽器中直接使用 https://registry.ntpstat.com(換成你的域名)進行訪問。能夠看到,https 配置成功。
web 頁面配置 https 只是小試牛刀,主要仍是爲了證實證書沒有問題,固然也是爲了提高逼格。那麼接下來就要配置 docker 倉庫了,而這以前咱們先配置倉庫使用的存儲,將不一樣的倉庫的數據放在不一樣的目錄下,方便管理。
首先,在 nexus 的 web 界面上點擊右上角的 Sign in,使用默認 admin/admin123 進行登陸,登陸成功後,會出現一個小齒輪的圖標,點擊進去以後就能夠進行配置了。
咱們首先點擊 Repository 下面的 Blob Stores,點擊 create blob store 建立一個新的 blob store。
建立完成後,再建立一個:
兩個存儲路徑就建好了,一個是給外部鏡像使用的,另外一個給公司內部鏡像使用的。可是基本上公司內部的鏡像會放在 harbor 中,由於更好分類。
一樣是設置界面,咱們選擇 Blob Stores 的下一個選項 Repositories,咱們會在其下配置 docker 的鏡像倉庫。
首先點擊 Create repository -> docker(hosted):
Name
:docker-private;Online
:勾選;HTTP
:勾選,並輸入 8083 端口(這個端口隨意,後面對上就行);HTTPS
:不要管,https 咱們會在 nginx 上面配;Allow anonymous docker pull
:看須要了,若是你想拉鏡像的時候不須要登陸就勾選,我不勾選;Enable Docker V1 API
:若是你使用的 docker 版本夠新的話,能夠不勾選,我勾了;Blob store
:選擇以前建立的 docker-private;Strlct Content Type Validation
:貌似是要驗證 push 的鏡像的格式,我勾了;Deployment policy
:是否容許部署和更新鏡像啥的,沒弄懂,我選了 Allow redeploy;Available cleanup policles
:鏡像的清除策略,由於咱們還沒建立,所以沒得選,就先不選吧;這個 repository 就是用來放公司內部的鏡像,在咱們的計劃中它其實用不到,由於能夠用 harbor 來完成,可是不免有人會用到,所以一併建立了。下次再建立一個 repository,這個倉庫用來存放從 dockerhub 下載下來的官方鏡像。
Create repository -> docker(proxy):
Name
:docker-hub;Online
:勾選;remote storage
:https://registry-1.docker.io,這是 dockerhub 的地址;Docker Index
:Use Docker Hub;Auto blocking enabled
:勾選;Maximum component age
:緩存時間本身定就好,默認 1440 爲一天;Maximum metadata age
:使用默認值便可;Blob store
:選擇以前建立的 docker-hub;Not found cache enabled
:鏡像沒有找到是否緩存,默認緩存,按默認來;Not found cache TTL
:緩存時長使用默認值便可;沒有提到的選項不用管,而後就建立完畢了。使用它能夠從 docker hub 上下載鏡像了,下載的方式下面會講到。它應該還能夠配置從 k8s.gcr.io 下載,這裏的鏡像是 docker hub 中沒有的,有興趣的能夠試試。
接下來還得建立一個 repository,這個倉庫用來分組,將上面兩個倉庫合併在一塊兒,經過都一個端口來同時訪問它們。
Create repository -> docker(group):
Name
:docker-group;Online
:勾選;HTTP
:8082;Allow anonymous docker pull
:我沒有勾選,須要認證才能下載鏡像;Enable Docker V1 API
:若是你使用的 docker 版本夠新的話,能夠不勾選,我勾了;Blob store
:它只是一個組,不存聽任何東西,所以使用 default 便可;Member repositories
:將 docker-private 和 docker-hub 放到右邊;建立完畢以後,nexus 會自動啓動 8082 和 8083 端口。其中 8082 是用來 pull 私有倉庫和 dockerhub 鏡像的,8083 用來 push 鏡像到私有倉庫。如今要作的就是使用 nginx 爲這些端口配置 https。
咱們分別經過 2222 和 3333 端口來代理 8082 和 8083,而且在 2222 和 3333 上啓用 https,所以 docker 須要鏈接 2222 和 3333 端口。
# vim /etc/nginx/conf.d/nexus.conf
server {
listen 2222 ssl;
server_name registry.ntpstat.com;
ssl_certificate /etc/nginx/cert/fullchain.pem;
ssl_certificate_key /etc/nginx/cert/privkey.pem;
ssl_session_cache shared:SSL:50m;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// https://;
proxy_pass http://127.0.0.1:8082;
client_max_body_size 1024m;
client_body_buffer_size 128k;
}
}
server {
listen 3333 ssl;
server_name registry.ntpstat.com;
ssl_certificate /etc/nginx/cert/fullchain.pem;
ssl_certificate_key /etc/nginx/cert/privkey.pem;
ssl_session_cache shared:SSL:50m;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// https://;
proxy_pass http://127.0.0.1:8083;
client_max_body_size 1024m;
client_body_buffer_size 128k;
}
}
複製代碼
配置完成以後就可使用 docker login 命令驗證了。在此以前,若是你係統上配置的 dns 沒法解析 registry.ntpstat.com(替換成你的),你還須要將之添加到 hosts 文件中。這裏略過,直接驗證。
# docker login -u admin -p admin123 registry.ntpstat.com:2222
# docker login -u admin -p admin123 registry.ntpstat.com:3333
複製代碼
只要出現 Login Succeeded
表示驗證 ok,沒出現天然就是失敗了。
若是驗證失敗,你能夠在 /etc/docker/daemon.json
中下面這行,IP 換成 nexus 的 ip 或主機名均可以。
"insecure-registries" : ["IP:8082", "IP:8083"]
複製代碼
文件修改完畢以後,使用 python -mjson.tool </etc/docker/daemon.json
來驗證格式是否正確,而後重啓 docker。
這是使用 http 而非 https 的方式直接鏈接 nexus,若是驗證成功,那就是你 nginx 配置有問題。固然證書確定沒有問題,否則你 https 訪問 web 界面就必定不會是安全的。若是驗證失敗,那就是配置有問題了,照着上面仔細再配一遍吧。
# docker login -u admin -p admin123 IP:8082
# docker login -u admin -p admin123 IP:8083
複製代碼
若是你使用 ip 的方式登陸成功了,可是使用 https 死活都登陸不了,且 nginx 配置不存在問題的狀況下,多是你 docker 使用了代理,docker login 的請求轉發到代理服務器上去了。
此時你要檢查 docker systemd service 文件以及同一目錄下的 docker.service.d 目錄下的全部文件,看看這些文件中是否存在 HTTP_PROXY
這樣的配置,若是有,註釋後重啓 docker 再驗證。
這種狀況能夠經過抓包發現。
驗證成功以後就能夠下載鏡像了,nexus 能夠幫咱們從 dockerhub 上面下載鏡像,前提是你的 nexus 可以訪問 dockerhub。若是不能也沒關係,搭建一個代理服務吧。那若是說你連能夠上網的機器都沒有,那就沒辦法了,你能夠直接使用 harbor 了。
nexus 配置代理的方法也很簡單,管理員登陸 -> 點擊小齒輪圖標 -> System -> HTTP -> 勾選 HTTP proxy -> 添加主機和端口 -> Save。
這樣一來,你 nexus 全部的 http/https 請求都會經過這個代理進行。固然,若是有不須要代理的 ip 你能夠填在 Hosts to exclude from HTTP/HTTPS proxy 中。
如今你的 nexus 能上網了,那麼先下載個 busybox 鏡像吧。前面提到過,鏡像下載使用 2222 端口。
# docker login -u admin registry.ntpstat.com:2222
# docker pull registry.ntpstat.com:2222/busybox
Using default tag: latest
latest: Pulling from busybox
697743189b6d: Pull complete
Digest: sha256:4415a904b1aca178c2450fd54928ab362825e863c0ad5452fd020e92f7a6a47e
Status: Downloaded newer image for registry.ntpstat.com:2222/busybox:latest
複製代碼
若是你容許匿名 pull 就不須要登陸。
只須要將鏡像名寫在 registry.ntpstat.com:2222/
的後面便可,nexus 本地若是沒有,就會去 dockerhub 上下載。固然,這麼下載下來的鏡像名天然也就是很長的一串了。
上傳鏡像使用 3333 端口,咱們將剛剛下載下來的鏡像上傳。
# docker login -u admin registry.ntpstat.com:3333
# docker tag registry.ntpstat.com:2222/busybox registry.ntpstat.com:3333/busybox:test
# docker push registry.ntpstat.com:3333/busybox:test
The push refers to repository [registry.ntpstat.com:3333/busybox]
adab5d09ba79: Pushed
test: digest: sha256:4415a904b1aca178c2450fd54928ab362825e863c0ad5452fd020e92f7a6a47e size: 527
複製代碼
push 必須登陸。我這裏給 busybox 加了個 tag,只是爲了測試,沒有任何做用。那麼關於 nexus 做爲 docker 倉庫的內容也就這麼多了,接下來配置 harbor。
在安裝使用 harbor 以前,若是你的 harbor 和 nexus 都安裝在同一臺服務器上,你須要將代理 nexus 的 nginx 的 80 和 443 端口改掉,由於 harbor 會監聽這兩個端口。其實這樣一來的話,nginx 的 80 和 443 均可以不用了,直接使用 nexus 的 8081 訪問便可。
harbor 是 VMware 開源的 registry,也是一款大衆熟知的產品,它的 GitHub 地址在此。它的安裝只能經過 docker 進行,所以你得首先安裝 docker。
# yum install -y yum-utils device-mapper-persistent-data lvm2
# cat > /etc/yum.repos.d/docker-ce.repo <<'EOF'
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
EOF
# yum install docker-ce
# systemctl enable docker
# systemctl start docker
# systemctl status docker
複製代碼
你還得安裝 docker-compose,它用來定義和管理由多個容器構成的應用。很顯然,harbor 須要運行多個容器。
curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
複製代碼
以上前置條件都完成以後,下載 harbor 的離線包:
wget https://storage.googleapis.com/harbor-releases/release-1.7.0/harbor-offline-installer-v1.7.1.tgz
複製代碼
貌似被牆了,能夠經過國內鏡像下載,可是從我寫這篇文章時發現國內鏡像的最新版本才 1.5 而非 1.7。此次操做仍是經過 1.7 進行,1.5 應該和 1.7 安裝起來應該沒啥區別。固然,做爲一名技術人,基礎的**牆手段應該仍是應該具有的。
下載完成後先解壓:
tar xf harbor-offline-installer-v1.7.1.tgz
mv harbor /opt
cd harbor
複製代碼
在修改配置文件前,咱們須要首先得到 https 證書,https 證書我們已經獲取了,這裏就很少提了。咱們先看看它的 compose 配置,它定義了 harbor 所需全部鏡像的配置。
vim docker-compose.yml
複製代碼
能夠看到它將數據都保存在 /data
目錄下,若是你想要改的話,可使用 sed
直接替換。我這裏將其改成了 /opt/data
:
# 先查看改的對不對
sed -n 's@- /data/@- /opt/data/@gp' docker-compose.yml
# 確認 ok 以後,開幹
sed -i 's@- /data/@- /opt/data/@g' docker-compose.yml
# 將目錄建立出來
mkdir /opt/data
複製代碼
從 yml 文件咱們還能夠看到,它的 https 以及 web 服務器都是配置在 nginx 容器中的,且它是將 harbor/common/config/nginx 下面的全部文件都做爲 nginx 容器的配置文件。這個目錄目前並不存在,執行 prepare 腳本會建立。
其餘的有想改的能夠動手改,這裏就不改了。接着修改配置文件。
# vim harbor.cfg
hostname = registry.ntpstat.com
# 直接 https 搞起
ui_url_protocol = https
# 咱們有證書,不須要生成
customize_crt = off
# 指定證書文件
ssl_cert = /etc/nginx/cert/fullchain.pem
ssl_cert_key = /etc/nginx/cert/privkey.pem
# 由於我這裏改了它的存儲目錄,因此這裏也要改
secretkey_path = /opt/data
# 管理員密碼
harbor_admin_password = Harbor12345
複製代碼
還有其餘的配置,好比郵件以及 ldap 的,有興趣的能夠修改,這裏就略過了。
修改完成以後,執行 prepare 腳本:
# ./prepare
Generated and saved secret to file: /opt/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
Copied configuration file: ./common/config/coreprivate_key.pem
Copied configuration file: ./common/config/registryroot.crt
The configuration files are ready, please use docker-compose to start the service.
複製代碼
能夠看到,它生成了不少的配置文件,其中就有 nginx 的,它會將咱們在配置文件中指定的證書複製到 common/config/nginx/cert/
目錄下,這樣容器內的 nginx 就可以加載到了。你可使用 md5sum 命令來檢測兩個證書文件是否一致。
而後就能夠執行 install.sh 了,其實執行這個腳本的過程當中它會自動執行上面執行的 prepare 腳本:
# sh install.sh
...
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at https://registry.ntpstat.com.
For more details, please visit https://github.com/goharbor/harbor .
複製代碼
這種安裝方式不會安裝 Notary/Clair,若是要安裝它們,能夠給 install.sh 傳遞 --with-notary
和 --with-clair
參數。
你若是還但願使用 harbor 做爲 chart 倉庫,爲 helm 提供支持的話,能夠給 install.sh 傳遞 --with-chartmuseum
。
安裝成功以後,會出現上面結尾的信息,而後瀏覽器直接訪問就好了,我這裏訪問的是 https://registry.ntpstat.com,大家訪問大家的。
而後就打開了 harbor 的 web 界面了,默認使用 admin/Harbor12345
直接登陸。你能夠直接建立不一樣的項目,也就是所謂的不一樣的目錄,而後將不一樣的鏡像放到不一樣的目錄下,這樣分類起來就很方便了,這也是 nexus 不具有的地方。
默認只有一個 library 項目,咱們如今往裏面上傳一個鏡像來了解它的操做。
# docker login -u admin -p Harbor12345 registry.ntpstat.com
# docker tag registry.ntpstat.com:2222/busybox registry.ntpstat.com/library/busybox
# docker push registry.ntpstat.com/library/busybox
The push refers to repository [registry.ntpstat.com/library/busybox]
adab5d09ba79: Pushed
latest: digest: sha256:4415a904b1aca178c2450fd54928ab362825e863c0ad5452fd020e92f7a6a47e size: 527
複製代碼
push 完成後,就能夠在 library 下面看到 busybox 這個鏡像了。harbor 和 nexus 不一樣,它上傳和下載鏡像都使用同一個端口。
pull 鏡像就很簡單了,將上面的 push 換成 pull 就好了,並且只要項目的訪問級別爲公開,那麼 pull 的時候都不用 login,這樣在寫腳本的時候會方便一點。固然,不公開也沒啥關係,無非就多了個登陸操做而已,在 k8s 中很容易作到。
咱們以前執行 install.sh 的時候自動將 harbor 拉起來了,總不能每次重啓都執行 install.sh 對吧。
它的中止和啓動的方式以下:
docker-compose stop
docker-compose start
複製代碼
若是你想要改變 harbor 配置,你應該使用上面的命令先中止 harbor,而後修改 harbor.cfg,執行 prepare 生成新的配置,而後啓動 harbor。整個過程以下:
# docker-compose down -v
# vim harbor.cfg
# prepare
# docker-compose up -d
複製代碼
好了,這篇文章就寫到這裏了,這只是個掃盲文章,更深刻的東西就要靠大家本身研究了。