首页 > 技术文章 > docker安装指定版本nexus3

moris5013 2019-08-31 22:26 原文

安装maven私服

1 下载指定版本的镜像

 docker  pull  sonatype/nexus3:3.18.1

2 宿主机创建一个映射目录 ,并设置所有者

mkdir  -p  /app/nexus3/nexus-data 

chown -R 200 /app/nexus3/nexus-data   (意思是,给这目录分配了UID为200的用户,nexus3会使用UID为200的用户操作该目录,否者会报错)

3 启动容器

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

4 查看nexus3是否启动成功了

curl http://localhost:8081

5 查看容器日志

docker  logs -f  containerId

 6 参考

https://hub.docker.com/r/sonatype/nexus3

 

上传jar包到maven私服

1  创建私服仓库

创建仓库,点击Create repository,然后选择maven2(hosted)然后输入仓库名称(test-release)。在version policy中选择这个仓库的类型,这里选择release,Deployment policy中选择Allow redeploy

2  创建私服账号

 

点击左侧菜单栏的Security下的Users菜单,然后点击Create local user.我这里创建了一个用户,账号密码都是mouse

3 更改maven本地setting.xml文件,新增节点。这里的文件指的是maven安装目录中的配置文件

     <server>
          <id>mouse</id>
          <username>mouse</username>
          <password>mouse</password>
      </server>

 

4 更改项目中的pom.xml文件 

    <distributionManagement>
        <repository>
            <!--此名称要和.m2/settings.xml中设置的ID一致 -->
            <id>mouse</id>
            <url>http://192.168.101.201: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>

5 在项目根目录执行程序

mvn deploy  这里要注意的是项目打包是release版本,才可以上传成功,否者会报错

6 可以在maven私服中看到刚才上传的jar包了

 

从maven私服下载jar包

1 在项目的pom.xml文件中添加下面配置

    <repositories>
        <repository>
            <id>mouse</id>
            <url>http://192.168.212.230:8081/repository/mayikt-release/</url>
        </repository>
    </repositories>

 

推荐阅读