docker私服搭建有官方的registry镜像,也有改版后的NexusOss3.x,由于maven的缘由搭建了nexus,因此一并将docker私服也搭建到nexus上。node
nexus的安装过程就单独说了,若是是2.x系列须要升级到2.14版本再升级到3.y系列,若是3.x到3.y直接升级就能够。docker
从3.0版本开始,nexus再也不只是一个maven仓库,还能够是docker、npm、bower的私有仓库。shell
docker的仓库连接是基于HTTPS的,故通常状况下须要将nexus的访问方式改成支持https。
配置SSL主要的难点在于证书,证书能够用公网证书,而通常状况下,私服部署在内网,没有域名,用内网IP访问,这种状况下用自签名的证书是最好的选择。证书生成工具用jdk自带的就能够。
配置过程,进入${nexus}/etc/ssl目录下面,执行命令过程当中会输入屡次密码,记下密码,后面有用处:npm
$ keytool -genkeypair -keystore example.jks -storepass password -alias example.com \ > -keyalg RSA -keysize 2048 -validity 5000 -keypass password \ > -dname 'CN=*.example.com, OU=Sonatype, O=Sonatype, L=Unspecified, ST=Unspecified, C=US' \ > -ext 'SAN=DNS:nexus.example.com,DNS:clm.example.com,DNS:repo.example.com,DNS:www.example.com' Warning: The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore example.jks -destkeystore example.jks -deststoretype pkcs12". $ keytool -exportcert -keystore example.jks -alias example.com -rfc > example.cert Enter keystore password: password Warning: The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore example.jks -destkeystore example.jks -deststoretype pkcs12". $ keytool -importkeystore -srckeystore example.jks -destkeystore example.p12 -deststoretype PKCS12 Importing keystore example.jks to example.p12... Enter destination keystore password: Re-enter new password: Enter source keystore password: Entry for alias example.com successfully imported. Import command completed: 1 entries successfully imported, 0 entries failed or cancelled $ openssl pkcs12 -nocerts -nodes -in example.p12 -out example.key Enter Import Password: MAC verified OK
修改配置文件:etc/nexus.propertiesjson
原: nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml 修改后: application-port-ssl=8433 nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-https.xml,${jetty.etc}/jetty-requestlog.xml
修改配置文件:etc/jetty/jetty-https.xml浏览器
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory"> <Set name="KeyStorePath"><Property name="ssl.etc"/>/keystore.jks</Set> // 文件名和前面证书的一致 <Set name="KeyStorePassword">password</Set> // 密码用前面的 <Set name="KeyManagerPassword">password</Set> <Set name="TrustStorePath"><Property name="ssl.etc"/>/keystore.jks</Set> <Set name="TrustStorePassword">password</Set> <Set name="EndpointIdentificationAlgorithm"></Set> <Set name="NeedClientAuth"><Property name="jetty.ssl.needClientAuth" default="false"/></Set> <Set name="WantClientAuth"><Property name="jetty.ssl.wantClientAuth" default="false"/></Set> <Set name="ExcludeCipherSuites"> <Array type="String"> <Item>SSL_RSA_WITH_DES_CBC_SHA</Item> <Item>SSL_DHE_RSA_WITH_DES_CBC_SHA</Item> <Item>SSL_DHE_DSS_WITH_DES_CBC_SHA</Item> <Item>SSL_RSA_EXPORT_WITH_RC4_40_MD5</Item> <Item>SSL_RSA_EXPORT_WITH_DES40_CBC_SHA</Item> <Item>SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA</Item> <Item>SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA</Item> </Array> </Set> </New>
重启nexus,打开浏览器访问,https://ip:8443/ 会提示出来证书签名有问题,直接略过就行。app
建立三个仓库,若是须要代理多个来源,能够建立多个代理库。
私有仓库:注意将http或者https的端口打开。eclipse
代理中央库的注意地址:
remote: https://registry-1.docker.io
docer index : use Docker hubmaven
组合仓库将刚创建的Hosted和Proxy仓库都加入就能够了。工具
本地配置最主要的是配置insecure-registries和docker login。
/etc/docker/daemon.json
{ "registry-mirrors": ["https://IP:18443"], "insecure-registries":["IP:18443","IP:18444"] }
为何须要两个insecure-registry呢?由于group仓库不能够做为push仓库,若是单纯的进行pull,能够只配置一个。
分别login两个insecure-registry。
$ docker login IP:18444 Username (admin): admin Password: Login Succeeded $ docker login IP:18443 Username (admin): admin Password: Login Succeeded
这样能够愉快的进行push和pull操做了。
nexus有一个设定,push只能对Hosted,pull从三种仓库均可以。由于push的操做给proxy的,是没法推送给被代理库的。group的仓库接受push后,没法肯定是给proxy仍是hosted。
可是nexus能够经过push给hosted的仓库,可是经过group仓库pull。
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest 3fd9065eaf02 5 months ago 4.15MB IP:18443/alpine latest 3fd9065eaf02 5 months ago 4.15MB $ docker tag alpine IP:18444/alpine $ docker push IP:18444/alpine The push refers to repository [IP:18444/alpine] cd7100a72410: Layer already exists latest: digest: sha256:8c03bb07a531c53ad7d0f6e7041b64d81f99c6e493cb39abba56d956b40eacbc size: 528 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest 3fd9065eaf02 5 months ago 4.15MB IP:18444/alpine latest 3fd9065eaf02 5 months ago 4.15MB $ docker pull IP:18443/alpine Using default tag: latest latest: Pulling from alpine Digest: sha256:8c03bb07a531c53ad7d0f6e7041b64d81f99c6e493cb39abba56d956b40eacbc Status: Image is up to date for IP:18443/alpine:latest $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest 3fd9065eaf02 5 months ago 4.15MB IP:18443/alpine latest 3fd9065eaf02 5 months ago 4.15MB IP:18444/alpine latest 3fd9065eaf02 5 months ago 4.15MB
完成。