docker部署nexus并啟用https方式
docker部署nexus并啟用https
實現(xiàn)目標(biāo)
- docker 運行nexus
- nexus docker倉庫支持https
- docker client只需要把ca證書放到docker目錄下,不需要整個機器信任。
- nexus用 ip:port的方式訪問
構(gòu)建nexus鏡像
生成證書
# 這里的ip換為nexus運行機器的ip echo subjectAltName = IP:10.110.25.191 > extfile.cnf # 生成ca openssl genrsa -out ca.key 2048 openssl req -x509 -new -nodes -key ca.key -days 5000 -out ca.crt # 生成server證書 openssl genrsa -out server.key 2048 openssl req -new -key server.key -subj "/CN=10.110.25.191" -out server.csr openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out server.crt -days 5000 # 將證書導(dǎo)出成pkcs格式 # 這里需要輸入密碼 用password,如果不用這個,需要修改鏡像里的${jetty.etc}/jetty-https.xml,具體操作參考百度。 openssl pkcs12 -export -out keystore.pkcs12 -inkey server.key -in server.crt
構(gòu)建鏡像
FROM sonatype/nexus3 USER root COPY keystore.pkcs12 /keystore.pkcs12 RUN keytool -v -importkeystore -srckeystore keystore.pkcs12 -srcstoretype PKCS12 -destkeystore keystore.jks -deststoretype JKS -storepass password -srcstorepass password &&\ cp keystore.jks /opt/sonatype/nexus/etc/ssl/ USER nexus
docker build ./ -t nexus-https
啟動
# 8443是nexus ui https訪問端口 # 8081是nexus ui http訪問端口 # 8082將要用來作為docker代理docker hub的端口 # 8083將要用來作為docker本地倉庫的端口 docker run -d --restart=always -p 8443:8443 -p 8081:8081 -p 8082:8082 -p 8083:8083 --name nexus3 -v /docker/nexus/nexus-data:/nexus-data nexus-https:latest # 修改nexus的目錄權(quán)限 chmod -R 777 /docker # 等容器啟動,可以正常訪問頁面之后修改配置文件,開啟ssl vim /docker/nexus/nexus-data/etc/nexus.properties # 內(nèi)容如下: # Jetty section application-port-ssl=8443 application-port=8081 application-host=0.0.0.0 nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml,${jetty.etc}/jetty-https.xml nexus-context-path=/${NEXUS_CONTEXT} #Nexus section nexus-edition=nexus-pro-edition nexus-features=\ nexus-pro-feature nexus.clustered=false # 重啟容器 docker restart nexus3
創(chuàng)建倉庫
設(shè)置realms
在realms中把 docker bearer token realm 選為 active
創(chuàng)建docker的代理倉庫,代理docker hub
設(shè)置 -> repositories -> create repositories -> docker(proxy)
把https的選項選上,端口號填寫8082,Docker index 選擇Docker Hub,其他的按照默認(rèn)填寫
client訪問
在client端的服務(wù)器上創(chuàng)建 /etc/docker/certs.d/<nexus ip>:8082/文件夾。
將生成ca證書步驟生成的 ca.crt復(fù)制到 這個文件夾中。
docker login 試一下。
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Windows11安裝Docker Desktop教程的圖文教程
本文主要介紹一下Windows11安裝Docker Desktop教程的圖文教程,文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-10-10CentOS7使用docker部署Apollo配置中心的實現(xiàn)
這篇文章主要介紹了CentOS7使用docker部署Apollo配置中心的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10yum下載rpm以及相關(guān)依賴的方式離線安裝docker
今天小編就為大家分享一篇關(guān)于yum下載rpm以及相關(guān)依賴的方式離線安裝docker,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12