文章目录
一、在容器中安装运行nexus3
为了方便起见,这里使用脚本来处理安装运行。
在一个空目录中新建一个shell脚本文件,比如gen.sh,内容如下
# 所有操作在子目录中完成
mkdir -p output
cd output
# 创建辅助文件
echo subjectAltName=IP:192.168.1.8 > extfile.cnf
# 生成ca证书
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -days 10000 -out ca.crt
# 如果不想交互输入证书的国家,城市,公司名等等信息,可以在上面的命令加上参数:-subj "/CN=*"
# 生成server证书
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=192.168.1.8" -out server.csr
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out server.crt -days 10000
# 将证书导出成pkcs格式
# 这里需要输入密码 输入“password”,如果不用这个,需要修改镜像里的${jetty.etc}/jetty-https.xml对应的password
openssl pkcs12 -export -out keystore.pkcs12 -inkey server.key -in server.crt
# 复制需要的文件到上层目录
cp keystore.pkcs12 ..
# 复制ca.crt到系统
sudo cp ca.crt /usr/local/share/ca-certificates/nexus3.crt
# 更新证书
sudo update-ca-certificates
# 删除辅助文件
rm extfile.cnf
cd ..
# 构建镜像
sudo podman build -t nexus3-https:v1 .
# 创建主机映射目录
sudo mkdir -p /nsd/nexus
sudo chown 200:200 /nsd/nexus -R
# 启动镜像
# 8433作为nexus3 web的https端口
# 8081作为nexus3 web的http端口
# 5051作为docker 本地仓库的端口
# 5052作为docker 代理的端口
sudo podman run -d --restart=always --rm