7

Docker Nexus 使用dnspod证书

 4 years ago
source link: http://www.chenshake.com/docker-nexus-uses-a-dnspod-certificate/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

 

最近搞HTTPS,顺便提升一下自己的docker水平。现在需要内网搭建一个Nexus服务器,用来mirror docker镜像。希望可以实现https访问nexus,而且是用域名。我肯定使用的是私有ip地址。

配置nexus 使用HTTP访问,有两种方式,一种就是前端加上Nginx,另外一种就是配置Nexus。我选择了使用配置Nexus。

DNSPod,创建一个主机,生成证书

申请ssl证书,下载到本地,上传到服务器上,证书里有一个Tomcat 目录,

 ll Tomcat/
总用量 12
-rw-r--r-- 1 root root   15 8月  12 12:18 keystorePass.txt
-rw-r--r-- 1 root root 6175 8月  12 12:18 nexus.chenshake.site.jks

默认官方nexus镜像,是不带https,那么你需要找一个支持HTTPS的镜像。

  • https://github.com/bradbeck/nexus-https

作者提供的镜像,使用自己签发的证书。我就直接利用这个镜像

mkdir -p /data/nexus/nexus-data
mkdir -p /data/nexus/nexus-ssl
chown -R 200 /data/nexus/nexus-data
chown -R 200 /data/nexus/nexus-ssl
docker run -d -p 8081:8081 -p 8443:8443 \
-v /data/nexus/nexus-data:/nexus-data \
-v /data/nexus/nexus-ssl:/opt/sonatype/nexus/etc/ssl \
--name nexus \
bradbeck/nexus-https

正常来说,你就会启动一个nexus的镜像,你可以尝试使用ip地址直接访问

  • http://ip:8081
  • https://ip:8443

用户名admin,密码已经不是以前的admin123,关于nexus的密码,已经是随机生成,我们给nexus挂的存储里,就能找到随机的密码。

cat /data/nexus/nexus-data/admin.password 
e43a80cd-7eda-49f1-8290-0d5a9155aad9

我希望使用dnspod签发的证书,来替换自己签发的证书。证书专门挂了一个目录

cd /data/nexus/nexus-ssl/
mv keystore.jks keystore.jks.save
cp /home/Tomcat/nexus.chenshake.site.jks ./keystore.jks

这样就更换了证书,还需要修改一下这个证书的密码,这个需要进入容器里修改

docker exec -it nexus /bin/bash
vi /opt/sonatype/nexus/etc/jetty/jetty-https.xml 

这里就是我下载证书的密码,替换掉。文件里默认的密码是:password

cat /home/Tomcat/keystorePass.txt 
qfyk296s170r4e2
:%s/password/qfyk296s170r4e2/g

保存退出后。我们是修改了docker里面的文件,我们需要重新保存一下。commit后面的id,就是镜像运行的id号,docker ps查看。

docker commit 3a6b714db9ed shake/nexus33:v1.0

查看一下提交的情况

# docker images
REPOSITORY             TAG       IMAGE ID       CREATED          SIZE
shake/nexus33          v1.0      a3e34306a3ad   30 minutes ago   823MB
<none>                 <none>    710e75f478e3   40 minutes ago   850MB
bradbeck/nexus-https   latest    f2bdbff829e0   6 days ago       822MB
sonatype/nexus3        latest    84bed2486e46   7 days ago       655MB

把启动的docker nexus stop,删掉,重新启动

docker stop nexus
docker rm nexus

用定制过的镜像,重新启动

docker run -d -p 8081:8081 -p 8443:8443 \
-v /data/nexus/nexus-data:/nexus-data \
-v /data/nexus/nexus-ssl:/opt/sonatype/nexus/etc/ssl \
 --name nexus -d shake/nexus33:v1.0

如果可以正常启动,其实就说明都生效了。因为如果有问题,镜像就根本没法启动。

  • https://nexus.chenshake.site:8443

非常完美。

  • https://zhuanlan.zhihu.com/p/63055844
  • https://devops.stackexchange.com/questions/9614/how-to-setup-docker-mirror-proxy-repository-in-nexus-repository-manageross-3-19
  • https://mtijhof.wordpress.com/2018/07/23/using-nexus-oss-as-a-proxy-cache-for-docker-images/

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK