前提:
docker已经安装成功
1、下载一个nexus3的镜像
docker pull sonatype/nexus3
2、将容器内部/var/nexus-data挂载到主机/root/nexus-data目录。
docker run -d -p 8081:8081 --name nexus -v /root/nexus-data:/var/nexus-data --restart=always sonatype/nexus3
注意:查看镜像信息
docker images
查看启动的容器
docker ps -a
查看容器的信息
docker inspect e759d586cb1c 【e759d586cb1c,看上图中的NAMES,容器的id值】
测试IPAddress的值,如
curl 172.17.0.2:8081 【如果出现拒绝连接,执行ping 172.17.0.2 】
关闭防火墙
systemctl stop firewalld.service
至此,等待2-3分钟,然后浏览器访问
http://ip:8081 搭建成功
默认登陆账号 admin admin123
创建前的准备
http://maven.aliyun.com/nexus/content/repositories/central/
创建仓库,点击
Create repository
然后选择
maven2(hosted)
然后输入仓库名称(test-release)
在version policy中选择这个仓库的类型,这里选择release,
在Deployment policy中选择Allow redeploy(这个很重要).
创建私服账号
点击左侧菜单栏的Users菜单,然后点击Create local user.我这里创建了一个用户,账号密码都是:kejun
修改本地maven的配置文件,settings.xml
<servers>
<server>
<id>myRepositories</id>
<username>kejun</username>
<password>kejun</password>
</server>
</servers>
创建一个Maven工程
创建一个maven工程,并且打包到maven私服。
pom.xml配置如下
<!--注意限定版本一定为RELEASE,因为上传的对应仓库的存储类型为RELEASE -->
<!--指定仓库地址 -->
<distributionManagement>
<repository>
<!--此名称要和.m2/settings.xml中设置的ID一致 -->
<id>myRepositories</id>
<url>http://192.168.1.114:8081/repository/test-release/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<!--发布代码Jar插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<!--发布源码插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
部署
mvn deploy
测试
<dependencies>
<dependency>
<groupId>com.nexus.package</groupId>
<artifactId>MavenCheck</artifactId>
<version>0.0.1-release</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>myRepositories</id>
<url>http://192.168.1.114:8081/repository/test-release/</url>
</repository>
</repositories>