Nexus 搭建docker本地仓库(hosted)和私有仓库(proxy)
2018-03-23 17:02
861 查看
本文主要参考“使用 Nexus 搭建 Docker 仓库”,在安装过程中遇到一些问题,本文中一并总结。在此对原作者表示感谢!
环境说明:
Centos 7.4
OpenJDK 8
Nexus 3.2.0
安装OpenJDK:
Description=nexus
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nexus-3.2.0-01/bin/nexus start
ExecReload=/usr/local/nexus-3.2.0-01/bin/nexus force-reload
ExecStop=/usr/local/nexus-3.2.0-01/bin/nexus stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target然后设置开启自启动:$ sudo systemctl enable nexus.service配置Nexus:
Nexus启动比较慢,可以通过netstat查看服务是否启动完成:$ sudo netstat -apn |grep 8081如果8081端口被其他应用占用,可以修改Nexus的配置文件修改application-port为其他端口:$ sudo vim /usr/local/nexus-3.2.0-01/etc/nexus-default.properties然后,重新启动Nexus。
对于docker仓库分为三类,分别是proxy、hosted、group,含义如下:
hosted,本地代理仓库,通常我们会部署自己的构件到这一类型的仓库,可以push和pull。
proxy,代理的远程仓库,它们被用来代理远程的公共仓库,如maven中央仓库,只能pull,proxy仓库可以用来加速。
group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置maven依赖仓库组,只能pull。
然后为该仓库起一个名字,如test。填写访问端口,如1234。如下图,
最后创建仓库即可。
然后重启docker服务:$ sudo systemctl daemon-reload
$ sudo systemctl restart docker.service
以本地已有的nginx为例:
测试pull功能:
创建过程与hosted相似,修改内容包括:Name: test
HTTP: 8888
Enable Docker V1 API: true 勾选下面的复选框
Remote storage: https://registry-1.docker.io Docker Index: Use Docker Hub
Blob store: default其中,名字任意,连接方式选HTTP,端口号任意,其余按照上面的设置。
最后创建仓库即可。
$ sudo systemctl restart docker.service
参考资料:
1. https://mritd.me/2017/01/08/set-up-docker-registry-by-nexus/ 2. http://www.cnblogs.com/wzy5223/p/5410990.html
3. https://blog.csdn.net/a286352250/article/details/52604846
环境说明:
Centos 7.4
OpenJDK 8
Nexus 3.2.0
安装OpenJDK:
1 在oracle官网下载安装包:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html2 用rpm安装:
$ sudo rpm -i jdk-8u91-linux-x64.rpm
3 配置环境变量(具体jdk版本号需要进入/usr/java文件夹查看):
$ export JAVA_HOME=/usr/java/jdk1.8.0_161
4 验证是否安装成功:
$ java -version openjdk version "1.8.0_161" OpenJDK Runtime Environment (build 1.8.0_161-b14) OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)安装Nexus:
1 下载、解压Nexus安装包:
$ wget --no-check-certificate https://download.sonatype.com/nexus/3/nexus-3.2.0-01-unix.tar.gz $ tar -zxvf nexus-3.2.0-01-unix.tar.gz $ sudo mv nexus-3.2.0-01 /usr/local
2 创建nexus用户:
$ sudo adduser -r -s /sbin/nologin -d /data/nexus-data nexus
3 创建sonatype-work 工作目录:
# 创建基本目录结构 $ sudo mkdir -p /usr/local/sonatype-work # 创建建数据目录 $ sudo mkdir -p /data/nexus-data/{etc,log,tmp} # 将数据目录软连接到工作目录 $ sudo ln -s /data/nexus-data /usr/local/sonatype-work/nexus3 # 更新所有目录权限 $ sudo chmod -R 755 /usr/local/{sonatype-work,nexus-3.2.0-01} /data/nexus-data $ sudo chown -R nexus:nexus /usr/local/{sonatype-work,nexus-3.2.0-01} /data/nexus-data
4 以前台或后台方式启动Nexus:
# 以前台方式运行 $ sudo -u nexus /usr/local/nexus-3.2.0-01/bin/nexus run # 后台运行 $ sudo -u nexus /usr/local/nexus-3.2.0-01/bin/nexus start
5 设置Nexus开机自启动:
$ sudo vim /etc/systemd/system/nexus.service添加如下内容:[Unit]
Description=nexus
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nexus-3.2.0-01/bin/nexus start
ExecReload=/usr/local/nexus-3.2.0-01/bin/nexus force-reload
ExecStop=/usr/local/nexus-3.2.0-01/bin/nexus stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target然后设置开启自启动:$ sudo systemctl enable nexus.service配置Nexus:
1 浏览器访问Nexus主机+port,Nexus默认使用8081端口:
如,http://192.168.13.197:8081/Nexus启动比较慢,可以通过netstat查看服务是否启动完成:$ sudo netstat -apn |grep 8081如果8081端口被其他应用占用,可以修改Nexus的配置文件修改application-port为其他端口:$ sudo vim /usr/local/nexus-3.2.0-01/etc/nexus-default.properties然后,重新启动Nexus。
2 登录:
默认账号为admin,默认密码为admin1233 创建仓库:
按下图1、2、3步执行:对于docker仓库分为三类,分别是proxy、hosted、group,含义如下:
hosted,本地代理仓库,通常我们会部署自己的构件到这一类型的仓库,可以push和pull。
proxy,代理的远程仓库,它们被用来代理远程的公共仓库,如maven中央仓库,只能pull,proxy仓库可以用来加速。
group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置maven依赖仓库组,只能pull。
3.1 本地docker仓库:
3.1.1 创建本地docker仓库(docker hosted):
选择docker(hosted)然后为该仓库起一个名字,如test。填写访问端口,如1234。如下图,
最后创建仓库即可。
3.1.2 修改所有使用Nexus仓库的节点上docker配置:
$ sudo vim /etc/docker/daemon.json添加如下绿框内容,其中ip只要客户端节点使用该ip能够访问Nexus服务器即可,端口为上面设置的端口号:
然后重启docker服务:$ sudo systemctl daemon-reload
$ sudo systemctl restart docker.service
3.1.3 验证本地docker仓库(docker hosted):
在客户端节点登录docker仓库:$ docker login -u admin -p admin123 12.12.10.13:1234测试push功能:以本地已有的nginx为例:
$ docker tag nginx/nginx:latest 12.12.10.13:1234/nginx/nginx:latest $ docker push 12.12.10.13:1234/nginx/nginx:latest此时,在Nexus上的test仓库中可以看到nginx/nginx。
测试pull功能:
$ docker pull 12.12.10.13:1234/nginx/nginx:latest可以将nginx镜像pull到本地。
3.2 代理docker仓库:
3.2.1 创建代理docker仓库(docker proxy):
选择docker(proxy)创建过程与hosted相似,修改内容包括:Name: test
HTTP: 8888
Enable Docker V1 API: true 勾选下面的复选框
Remote storage: https://registry-1.docker.io Docker Index: Use Docker Hub
Blob store: default其中,名字任意,连接方式选HTTP,端口号任意,其余按照上面的设置。
最后创建仓库即可。
3.2.2 修改所有使用Nexus仓库的节点上docker配置:
$ sudo vim /etc/docker/daemon.json在上面添加的“12.12.10.13:1234”后面添加“12.12.10.13:8888”,两者用逗号分隔。然后重启docker服务:$ sudo systemctl daemon-reload
$ sudo systemctl restart docker.service
3.2.3 验证代理docker仓库(docker proxy):
在客户端节点登录docker仓库:$ docker login -u admin -p admin123 12.12.10.13:8888测试pull功能:$ docker pull 12.12.10.13:1234/tensorflow/tensorflow:latest可以将tensorflow镜像pull到本地,并且在Nexus上有缓存,其他节点再pull该镜像的时候可以直接从Nexus服务器上拉取。
参考资料:
1. https://mritd.me/2017/01/08/set-up-docker-registry-by-nexus/ 2. http://www.cnblogs.com/wzy5223/p/5410990.html
3. https://blog.csdn.net/a286352250/article/details/52604846
相关文章推荐
- docker本地私有仓库搭建
- Docker搭建本地私有仓库
- Docker搭建本地私有仓库
- Docker搭建本地私有仓库
- 4.Docker搭建本地私有仓库
- Docker搭建本地私有仓库的详细步骤
- Docker搭建本地私有仓库
- Docker基础-搭建本地私有仓库
- Docker搭建本地私有仓库
- Docker CentOS服务器搭建本地私有仓库
- sonatype nexus 3搭建Docker私有仓库
- docker学习笔记(二)——本地私有仓库Registry的搭建与验证
- docker 搭建本地私有仓库 (v2)
- docker私有仓库registry的本地搭建
- centos 7.1搭建docker本地私有仓库返回500错误
- sonatype nexus 3搭建Docker私有仓库
- docker学习笔记三搭建本地私有仓库
- Nexus3 仓库搭建(基于Docker)
- 一步步搭建docker私有仓库并从私有仓库中下载镜像
- Docker 搭建私有仓库