查询可用镜像
我的操作环境是ubuntu
docker search nexus
选择这个使用人数最多的
下载镜像
docker pull sonatype/nexus3
启动镜像
# 8443是nexus ui https访问端口
# 8081是nexus ui http访问端口
# 8082将要用来作为docker代理docker hub的端口
# 8083将要用来作为docker本地仓库的端口
docker run -d --restart=always -p 8443:8443 -p 8081:8081 -p 8082:8082 -p 8083:8083 --name nexus3 -v /home/ubuntu/nexus/nexus-data:/nexus-data sonatype/nexus3
# 修改nexus的目录权限为777
chmod -R 777 /home/ubuntu/nexus/nexus-data
docker-compose部署
基本和前面差不多,只是多了个yml把命令写入了
version: '3'
services:
nexus:
image: sonatype/nexus3:3.56.0
container_name: nexus3
ports:
- "8081:8081"
volumes:
- ./data:/nexus-data
# root权限
privileged: true
登录
查看密码,用户默认是admin
,密码在admin.password
文件中,我在启动镜像之前把nexus
的data
目录挂载出来了,如果没有挂载出来直接docker exec -it
登录容器进去查看也可以的。
http://localhost:8081/
登录后查看日志发现一个connect timeout
明显被墙了
登录成功
java 代码push jar到仓库
方法1:
maven settings.xml
文件新增
密码填写自己配置的密码
<servers>
<server>
<id>releases-repo</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots-repo</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>public-repo</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
项目应用pom.xml
新增
<distributionManagement>
<repository>
<!--这里的id要和setting.xml中server下的id对应-->
<id>releases-repo</id>
<name>Nexus Releases</name>
<!--这里的路径建议到nexus页面中browse中去copy-->
<url>http://127.0.0.1:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots-repo</id>
<name>Nexus Repository</name>
<url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
maven deploy
上传到仓库
上传成功
如果项目中有一些模块不想上传/没有必要上传;(比如某个模块只是为了聚合其他模块,模块中只有一个pom
文件),可以通过pom
配置解决
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
公司其它团队引用jar
<repositories>
<repository>
<id>public-repo</id>
<url>http://127.0.0.1:8081/repository/maven-public/</url>
</repository>
</repositories>
<dependency>
<groupId>com.alibaba.blink</groupId>
<artifactId>flink-test-utils_2.11</artifactId>
<version>blink-3.2.2</version>
</dependency>