Docker 搭建maven私服

Docker 镜像docker-nexus3

1.创建data volume,用来持久化容器中的数据,保证容器删除重建后私服中的数据仍然存在

$ docker volume create --name nexus-data


2.启动nexus

$ docker run -d -p 8081:8081 --name nexus -v nexus-data:/nexus-data sonatype/nexus3


3.启动完成后可以通过host的ip:8081访问

[img]http://dl2.iteye.com/upload/attachment/0122/4825/1230b7a6-b09f-35ca-a766-e7f239600953.png[/img]

其中 [list]
[*]maven-central是个代理仓库,当我们需要的依赖在私服上不存在时,此仓库会直接从maven中央仓库中下载,并缓存到私服里面
[*]maven-public是一个仓库组,里面包含maven- releases和maven- snapshots以及maven-central,我们自己新创建的仓库需要加入到maven-public这个group中,这样使用这个私服的人只用配置一个maven-public的mirror就可以用私服里面的所有依赖
[*]maven-releases和maven-snapshots分别对应着发布版和快照版
[/list]

4.nexus默认用户是 admin/admin123,建议启动后修改密码,创建一个专门给开发人员用的用户,分给可以read、browse所有仓库的权限

5.使用maven私服
为了开发者的所有项目都自动采用搭建好的私服,需要在 .m2目录下追加如下配置文件





xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">


public
dev
dev222





public
central
internal nexus repository
http://IP:Port/repository/maven-public/




jdk-1.8


true
1.8


1.8
1.8
1.8



snapshots

true



public
http://IP:PORT/repository/maven-public/

true


true









注意dev是新创建的用户,此用户只有浏览,读取私服上依赖jar包的权限,对于需要上传文件到私服上的用户,需要用下面的配置
在.m2下的setting.xml文件的tag中追加如下配置段


xxxxx-releases
admin
admin123


xxxxx-snapshots
admin
admin123


其中xxxx-releases和xxxxx-snapshots是自己新创建的maven仓库,并且设置成可上传模式
上传到私服有两种格式
1.通过pom.xml上传
在项目对应pom.xml 文件,追加如下配置段



xxxxx-releases
xxxxx-releases
http://IP:Port/repository/xxxxx-releases/


xxxxx-snapshots
xxxxx-snapshots
http://IP:Port/repository/xxxxx-snapshots/



[b]此处配置的id需要和setting.xml中server的id保持一致[/b],之后就可以在工程目录下执行mvn deploy,将jar发布到私服的仓库中,jar以snapshots结尾的会自动发布到xxxxx-snapshots里面,没有的会直接发布到xxxxx-releases中

2.利用命令行上传第三方jar

mvn -X deploy:deploy-file -DgroupId=com.chengf -DartifactId=test -Dversion=1.0.0 -Dpackaging=jar -Dfile=test.jar -Durl=http://IP:Port/repository/xxxxx-releases/ -DrepositoryId=xxxxx-releases

[b]此处的repositoryId需要和setting.xml中server的id保持一致[/b]

你可能感兴趣的:(docker)