50010623 发表于 2017-2-28 07:01:18

试用 Nexus OSS 3.0 的docker仓库 (一)

  Nexus 3.0 可以创建三种docker仓库:
  1. docker (proxy)      代理和缓存远程仓库 ,只能pull
  2. docker (hosted)    托管仓库 ,私有仓库,可以push和pull
  3. docker (group)      将多个proxy和hosted仓库添加到一个组,只访问一个组地址即可,只能pull
  一. 配置Nexus 3.0
   经过测试, Nexus必须启动https,否则只能通过localhost登陆,hosted仓库也不能push。https证书可以到CA购买,也可以用自签名证书。 
      首先配置JVM1.8 ,下载安装Nexus 3.0,nexus-3.0.0-03-unix.tar.gz 。(下载需要代理,我已经上传到云盘:http://pan.baidu.com/s/1eRZesQe)
  解压压缩包以后,切换到解压目录,运行下面的命令就能启动



./bin/nexus run或者./bin/nexus start
  在启动之前需要先修改配置文件: (红色字体)
  1. 开启监听ssl协议端口



cat > etc/org.sonatype.nexus.cfg <<EOF
# Jetty section
application-port-ssl=8443
application-port=8081
application-host=0.0.0.0
nexus-args=${karaf.etc}/jetty.xml,${karaf.etc}/jetty-http.xml,${karaf.etc}/jetty-requestlog.xml,${karaf.etc}/jetty-https.xml,${karaf.etc}/jetty-http-redirect-to-https.xml
nexus-context-path=/
# Nexus section
nexus-edition=nexus-oss-edition
nexus-features=\
nexus-oss-feature
EOF
  2. 生成证书秘钥



NEXUS_DOMAIN=nexus 没有可以随便写
NEXUS_IP_ADDRESS=192.168.31.135 你的IP
mkdir etc/ssl
cd etc/ssl
keytool -genkeypair -keystore keystore.jks -storepass nexus3 -keypass nexus3 -alias jetty -keyalg RSA -keysize 2048 -validity 5000 -dname "CN=*.${NEXUS_DOMAIN}, OU=Example, O=Sonatype, L=Unspecified, ST=Unspecified, C=US" -ext "SAN=DNS:${NEXUS_DOMAIN},IP:${NEXUS_IP_ADDRESS}" -ext "BC=ca:true"
  3. 修改etc/jetty-https.xml ,红色字体



    <Set name="KeyStorePath"><Property name="karaf.etc"/>/ssl/keystore.jks</Set>
<Set name="KeyStorePassword">nexus3</Set>
<Set name="KeyManagerPassword">nexus3</Set>
<Set name="TrustStorePath"><Property name="karaf.etc"/>/ssl/keystore.jks</Set>
<Set name="TrustStorePassword">nexus3</Set>
  4. 启动Nexus3.0



./bin/nexus run
  5. 在运行docker的机器上信任nexus的证书, ubuntu系统



keytool -printcert -sslserver ${NEXUS_IP_ADDRESS}:8443 -rfc >nexus.crt
sudo mv nexus.crt /usr/local/share/ca-certificates/nexus.crt
sudo update-ca-certificates
  6. 重启docker



sudo service docker restart
  二. 创建docker代理仓库, docker (proxy)
  访问Nexus的主页,https://192.168.31.135:8443 ,(注,自签名证书需要在浏览器将地址添加到白名单,访问http协议的8081端口会自动跳转)
  用管理员登陆,用户名/密码 : admin/admin123,创建docker (proxy)仓库,内容如下面修改:



Name: docker
HTTPS: 8888
Enable Docker V1 API:true 勾选下面的复选框
Remote storage:https://registry-1.docker.io
Docker Index: Use Docker Hub
Blob store: default

  修改完成以后登陆代理仓库, 用户名密码: admin/admin123



docker login ${NEXUS_IP_ADDRESS}:8888
  
  然后可以用下面的命令搜索和下载docker镜像



docker search ${NEXUS_IP_ADDRESS}:8888/hello-world
docker pull ${NEXUS_IP_ADDRESS}:8888/hello-world
  下载成功以后,可以看到hello-world镜像已经缓存在nexus上了,其它机器再次下载速度就会快很多。

  试用 Nexus OSS 3.0 的docker仓库 (二): http://www.cnblogs.com/wzy5223/p/5414965.html
页: [1]
查看完整版本: 试用 Nexus OSS 3.0 的docker仓库 (一)