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 试一下。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我们构建服务的镜像,或者是个人生成的惊险,需要仓库的管理,作为docker常用的私服镜像仓库Nexus很友好的兼容...
    Lukes_zhai阅读 925评论 0 0
  • Nexus3.x 的私有仓库 启动 Nexus 容器 创建仓库 添加访问权限 NGINX 加密代理 Docker ...
    博客用户阅读 166评论 0 0
  • 目录 Docker Registry 介绍 Docker Registry 部署 1. Docker Regist...
    garyond阅读 4,782评论 2 8
  • 我是个很容易对事物着迷的人,偏偏好奇心也很旺盛,所以人生很多时候都是在入迷中度过的,并常常会达到心流的状态。...
    午后瞌睡猫阅读 809评论 0 0
  • 以下是常用手法: 如对面让你加微信或者QQ,发软件二维码,让你关注裸聊之类,可能对面录屏,以此要挟你,勿要精虫上脑...
    折御阅读 169评论 1 2