019.nexus搭建docker镜像仓库/maven仓库

时间:2023-03-08 20:01:20
019.nexus搭建docker镜像仓库/maven仓库

一、安装docker CE

  参考docker doc

  https://docs.docker.com/install/linux/docker-ce/centos/

二、docker启动nexus3

# .登录docker hub
docker login # .拉取nexus3镜像
docker pull sonatype/nexus3 # .查看镜像
docker images # .启动nexus3
docker run -id --name=nexus3 \
--privileged=true \
--restart=always \
-p : \
-p : \
-p : \
-p : \
-v /opt/nexus3/nexus-data:/var/nexus-data \
836c51250912 # 将容器的10000 10020端口映射到host机, 这些端口作为后续nexus3创建的docker镜像仓库支持docker访问的端口 # .查看nexus3日志
docker logs -f nexus3

三、启动nexus失败的问题

  如果服务器内存太小导致nexus无法启动,可以启用swap

  https://www.cnblogs.com/wuxie1989/p/5888595.html

  https://www.cnblogs.com/kerrycode/p/5246383.html

  https://www.cnblogs.com/bingyeh/p/5913486.html

Part one: nexus搭建docker镜像仓库

一、nexus3创建docker镜像仓库及用户、角色

  • 使用默认管理账号密码登录nexus3管理界面

  https://www.jianshu.com/p/77af52a75ad8

  https://segmentfault.com/a/1190000015629878

  登录地址: http://服务器ip:8081

  • 三种类型的docker镜像仓库

  hosted、proxy、group

  019.nexus搭建docker镜像仓库/maven仓库

  设置可以被docker-cli直接访问的端口(启动nexus容器的时候需要将这些端口暴露到host机);

  019.nexus搭建docker镜像仓库/maven仓库

  • 设置角色、创建用户

  创建角色、设置角色的权限;

  019.nexus搭建docker镜像仓库/maven仓库

  角色可以继承

  019.nexus搭建docker镜像仓库/maven仓库

  

  创建用户,为用户分配角色;

  019.nexus搭建docker镜像仓库/maven仓库

二、通过docker-cli使用镜像仓库

  • 设置docker-daemon的 insecure-registries
# .查看docker-daemon配置文件
systemctl status docker.service # .修改配置文件
vi /usr/lib/systemd/system/docker.service # ExecStart=/usr/bin/dockerd --insecure-registry 47.116.91.161: --insecure-registry 47.116.91.161: --insecure-registry 47.116.91.161: -H fd:// --containerd=/run/containerd/containerd.sock # .重启docker-daemon
systemctl daemon-reload # .重启docker
systemctl restart docker
  • 登录到nexus3搭建的docker镜像仓库

  docker login xxx:xxx:xxx:xxx:10010

Part Two: nexus搭建maven仓库

https://www.cnblogs.com/dreamroute/p/5440419.html

https://blog.csdn.net/ZZY1078689276/article/details/78953011

一、配置mavensettings.xml

安装完成的nexus已经创建了4个maven仓库

019.nexus搭建docker镜像仓库/maven仓库

## 私服的id需要与nexus仓库id保持一致
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin123</password>
</server>

二、修改项目pom.xml

## repository的id与ssettings.xml server id 一致
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>Nexus-Release-Repository</name>
<url>http://xx.xxx.xx.xxx:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>

三、maven build... > goals: deploy

jar包即可安装到本地仓库即上传到私服

四、SNAPSHOT版本

  • release正式仓库则是用来保存稳定的发行版本。

    编译打包时如果发现本地已经存在该版本的模块,则不会再去私服下载。

  • snapshot快照仓库用于保存开发过程中的不稳定版本,

    定义一个组件/模块为快照版本,只需要在pom文件中在该模块的版本号后加上-SNAPSHOT即可(注意这里必须是大写);

    mvn deploy时会自动发布到快照版本库中;

    其他工程使用该快照版本的模块如1.0-SNAPSHOT,即使本地仓库存在该快照版本模块1.0-SNAPSHOT,maven仍会自动从私服下载最新的快照版本。

    实际上发布到快照仓库后,Version为1.0-发布时间。

019.nexus搭建docker镜像仓库/maven仓库