docker 部署nexus并启用https

docker 部署nexus并启用https

实现目标
  1. docker 运行nexus
  2. nexus docker仓库支持https
  3. docker client只需要把ca证书放到docker目录下,不需要整个机器信任。
  4. nexus用 ip:port的方式访问

构建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
# 将证书导出成pkcs格式
# 这里需要输入密码  用password,如果不用这个,需要修改镜像里的${jetty.etc}/jetty-https.xml,具体操作参考百度。
openssl pkcs12 -export -out keystore.pkcs12 -inkey server.key -in server.crt

构建镜像

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的目录权限
chmod -R 777 /docker
# 等容器启动,可以正常访问页面之后修改配置文件,开启ssl
vim /docker/nexus/nexus-data/etc/nexus.properties


# 内容如下:
# 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

创建仓库

设置realms

在realms中把 docker bearer token realm 选为 active

创建docker的代理仓库,代理docker hub

设置 -> repositories -> create repositories -> docker(proxy)

把https的选项选上,端口号填写8082,Docker index 选择Docker Hub,其他的按照默认填写

client访问

在client端的服务器上创建 /etc/docker/certs.d/<nexus ip>:8082/文件夹。
将生成ca证书步骤生成的 ca.crt复制到 这个文件夹中。
docker login 试一下。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值