摘要:本文主要是记录如何使用 Nexus 3.3
官方的 Docker
镜像搭建 Maven 私服。基于 Dockder
搭建大大简化了整个流程。
众所周知,Docker
可以大大简化服务器的部署,所以 sonatype 公司也发布了 nexus v3版本的官方docker。有了这个 Dockerfile
我们就可以轻松的在本地或者自己的服务器搭建一个 Nexus
服务器了。
要运行,将暴露的端口8081绑定到主机
下载 Nexus 镜像
这里推荐的方案是利用 Docker 来搭建 Nexus 环境。这里默认大家已经都有 Docker 环境了。
首先利用下面的命令下载最新的 nexus 镜像
docker pull sonatype/nexus下载过程如下所示:
docker pull sonatype/nexus Using default tag: latest latest: Pulling from sonatype/nexus 8d30e94188e7: Pull complete 9b5961d40d03: Pull complete 074855ae6153: Pull complete cc0a3a494fba: Pull complete 8cfd0607bbfb: Pull complete Digest: sha256:6bb1966022009da38c4f679b51d2106f4d595aa7b887ac0bf93d14ebe4c0faa2 Status: Downloaded newer image for sonatype/nexus:latest
创建并启动 Nexus
首先创建一个数据卷容器,如下命令
docker run -d --name nexus-data sonatype/nexus echo "data-only container for Nexus"然后启动 Nexus
docker run -d -p 8081:8081 --name nexus --volumes-from nexus-data sonatype/nexus上面的命令中,将本机的 10081 端口映射到容器中的 8081 端口,并加载 数据卷容器 nexus-data。
创建容器过程需要一段时间时间进行初始化,可以用如下命令查看相关日志:
docker logs -f nexus在浏览器输入 http://localhost:8081/nexus/ 可以看到如下界面,说明 nexus 已经启动好了。
使用 Nexus
在这个私有库中,提供了一些仓库地址给我们使用,如下图所示:
关于每个仓库的意义何在,请移步到 Nexus 的官网中学习(文末给出了参考链接),此文不再进行介绍。
私有仓库的使用有两种方法,一种是对工程的 pom.xml 文件进行修改(这种方法只对 pom.xml 所属工程生效),如下所示:
将如下的repositories节点添加到 pom.xml 文件即可,Maven 会到此文件中配置的私有库,下载相应的依赖库。
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>testnexus</groupId> <artifactId>zzx</artifactId> <version>1.0-SNAPSHOT</version> <repositories> <repository> <id>nexus</id> <name>Team Nexus Repository</name> <url>http://localhost:10081/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.41</version> </dependency> </dependencies> </project>
另外一种方法就是直接修改 maven 的配置文件,这样所有工程默认都会使用私有库。如下所示:
在 ~/.m2/settings.xml
文件中,将 mirror 修改为:
<settings> <mirrors> <mirror> <!--This sends everything else to /public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:10081/nexus/content/groups/public</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!--Enable snapshots for the built in central repo to direct --> <!--all requests to nexus via the mirror --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
当利用 maven 进行工程打包时,可以看到,已经从私有库中下载依赖了(当在另外一台机器上使用相应的依赖库时,就直接使用私有库中所缓存的依赖了,不用再到互联网中下载,是不是很节约时间!):
testnesus mvn package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building zzx 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ Downloading: http://localhost:10081/nexus/content/groups/public/com/alibaba/fastjson/1.1.41/fastjson-1.1.41.pom Downloaded: http://localhost:10081/nexus/content/groups/public/com/alibaba/fastjson/1.1.41/fastjson-1.1.41.pom (9 KB at 2.9 KB/sec) Downloading: http://localhost:10081/nexus/content/groups/public/com/alibaba/fastjson/1.1.41/fastjson-1.1.41.jar Downloaded: http://localhost:10081/nexus/content/groups/public/com/alibaba/fastjson/1.1.41/fastjson-1.1.41.jar (350 KB at 16.5 KB/sec)
关于更多内容,请上 Nexus 的官网学习。
参考资料
相关推荐
文档图文并茂的详细描述了linux下Nexus 的部署,同时也提供了配置Nexus 代理docker的163镜像库的过程。 nexus支持搭建docker 仓库、maven仓库、yum仓库等 nexus主要类型仓库支持三种模式hosted、proxy、group每种...
docker-nexus, Sonatype Nexus的Docker 图像 sonatype/docker-nexus用于 Sonatype Nexus 存储库管理器 2的Docker 映像,。 对于 Nexus 存储库管理器 3,请参考 https://github.com/sonatype/docker-n
nexus清理docker私库
Nexus3构建Docker镜像仓库 使用Nexus3搭建一个docker的私服
本文档中包含了基本的软件安装使用,中间遇到的各种坑解决方案
主要介绍了使用Nexus创建Docker仓库的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
sonatype/docker-nexus 带有 OpenJDK 的 Sonatype Nexus Repository Manager 2 的 Docker 镜像,从 2.14.14 开始,用作基础镜像,而早期版本使用 CentOS。 对于 Nexus Repository Manager 3,请参考构建: # docker ...
sonatype-nexus-docker Sonatype Nexus 的 Docker 版本用法 docker run -p 8081:8081 --name nexus griff/sonatype-nexus然后将浏览器指向 或者使用明确指定的音量目标: mkdir -p /devdata/nexusdocker run -v /...
Docker-in-Action.pdf In 2011, I started working at Amazon.com. In that first week my life was changed as I learned how to use their internal build, dependency modeling, and deployment tool- ing. This ...
运行 Nexus 服务的 Docker 容器(Maven 存储库) 构建和运行服务 要构建图像: make 要测试服务: make check 向主机公开服务: docker run -d -p 8081:8081 snaekobbi/nexus-service 将服务暴露给另一个容器...
Applications can be packaged without worrying about environment-specific deployment concerns, and the operations team gets cleaner, more efficient systems across the board., Docker in Action starts ...
sonatype nexus 3搭建Docker私有仓库.docx
《Docker实战(In action中文版)》
Applications running inside containers share resources, making their footprints small.Docker in Action teaches readers how to create, deploy, and manage applications hosted in Docker containers....
docker-swarm-mode:设置基于Docker的CI环境。 工具包括GitLap,Jenkins,Sonarqube和Nexus
Fabric8 Maven 该docker映像包含一个原始映像以及必需的~/.m2/settings.xml配置,以便maven可以使用Kubernetes环境变量连接到Nexus。环境变量NEXUS_SERVICE_HOST和NEXUS_SERVICE_PORT是nexus服务器的主机/ ip和端口...
docker pull sonatype/nexus3 2.创建/usr/local/docker/nexus/docker-compose.yml文件 version: ‘3.1’ services: nexus: image: ‘sonatype/nexus3’ restart: always container_name: nexus ports: ...
An open source container system, Docker makes deploying applications painless and flexible. Docker is powerful and simple to use, and it makes life ...书中其他资源在 https://github.com/docker-in-practice
1、该文档介绍springboot项目docker打包具体步骤及项目相关配置,包含手动执行docker打包上传镜像和通过idea工具打包上传镜像。 2、介绍docker打包相关配置及注意...3、介绍springboot打包镜像上传nexus私有镜像仓库