docker搭建nexus3,配置setting.xml,以及maven工程deploy配置,docker镜像提交nexus3私有仓库...

1、拉取官方镜像

docker pull redis

2、运行容器

docker run -di -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084 --name=nexus3  -v /data/nexus-data:/nexus-data --privileged=true restart= always sonatype/nexus3

解释一下四个端口映射作用

8081:nexus3网页端

8082:docker(hosted)私有仓库,可以pull和push

8083 : docker(proxy)代理远程仓库,只能pull

8084:docker(group)私有仓库和代理仓库的组,只能pull

nexus-data目录 :docker里存放nexus数据目录,所有数据存放在宿主机/data/nexus-data

3、挂载目录授权

chown -R 200 /data/nexus-data/

 

4、重启容器

docker restart nexus3

5、创建docker私有仓库

06d66f2d4c7041d88cd28cc910f46b4c47b.jpg

fa06dc039496f5fb4414cc0cb079c242bbf.jpg

d2db2687e3a7f2d1a60ca655e89fd9b0ad5.jpg

 

ec69afa766a0a8b019b5ed424750df66ef3.jpg

 

b9bd6c3c09a59e6cbe4631e9b5010b431ea.jpg

 

6、测试提交镜像到nexus3创建的私有仓库

把本地的redis镜像打标签

docker tag redis 172.16.0.10:8082/redis

登录docker镜像仓库

docker login -u admin -p admin123 172.16.0.10:8082

提交镜像

 docker push 172.16.0.10:8082/redis

去nexus3的docker私有仓库查看镜像是否提交成功

33e610c0c42acf81bd41b7c3c829b53392e.jpg

下面附上提交镜像的操作轨迹图片

9bc40157c9dd81de94fd51a549872013c49.jpg

6、settings.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          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">

    <localRepository>/devs/software/repository</localRepository>
    <pluginGroups>
        <pluginGroup>com.spotify</pluginGroup>
    </pluginGroups>
    <proxies>

    </proxies>
    <servers>
        <!--公共组用户认证-->
        <server>
            <id>public</id>
            <username>deployment</username>
            <password>deployment</password>
        </server>
        <!--发布版本用户认证-->
        <server>
            <id>releases</id>
            <username>deployment</username>
            <password>deployment</password>
        </server>
        <!--快照版本用户认证-->
        <server>
            <id>snapshots</id>
            <username>deployment</username>
            <password>deployment</password>
        </server>
    </servers>
    <!--为仓库列表配置的下载镜像列表-->
    <mirrors>
        <mirror>
            <!--该镜像的唯一标识符。id用来区分不同的mirror元素-->
            <id>maven-public</id>
            <!--此处配置所有的构建均从私有仓库中下载 *代表所有-->
            <mirrorOf>*</mirrorOf>
            <!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL-->
            <url>http://192.168.100.101:8081/repository/maven-public/</url>
        </mirror>
    </mirrors>


    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>public</id>
                    <url>http://192.168.100.101:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>release</id>
                    <url>http://192.168.100.101:8081/repository/maven-releases/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <url>http://192.168.100.101:8081/repository/maven-snapshots/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>releases</id>
                    <url>http://192.168.100.101:8081/repository/maven-releases/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>snapshots</id>
                    <url>http://192.168.100.101:8081/repository/maven-snapshots/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        <!--设置maven编译级别-->
        <profile>
            <id>jdk18</id>
            <activation>
                <!--profile默认是否激活的标识-->
                <activeByDefault>true</activeByDefault>
                <!--activation有一个内建的java版本检测,如果检测到jdk版本与期待的一样,profile被激活-->
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>
    </profiles>
    <!--激活配置-->
    <activeProfiles>
        <activeProfile>releases</activeProfile>
    </activeProfiles>
</settings>

项目中pom.xml配置

<!--将项目发布到私服中-- 和build标签同一层级>
<distributionManagement>
    <repository>
        <id>releases</id>
        <name>maven-releases</name>
        <url>http://192.168.100.101:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>maven-releases</name>
        <url>http://192.168.100.101:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

加入deploy插件

<build>
 <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-deploy-plugin</artifactId>
     <version>2.8.2</version>
 </plugin>
  <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
      <version>2.4</version>
      <executions>
          <execution>
              <phase>package</phase>
              <goals>
                  <goal>jar</goal>
              </goals>
          </execution>
      </executions>
  </plugin>
</build>

最后执行 mvn deploy

转载于:https://my.oschina.net/shxjinchao/blog/3007168

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用MavenDocker插件,首先需要在Maven项目的pom.xml文件中添加插件配置。以下是一些示例配置,供您参考: ``` <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.2.0</version> <executions> <execution> <id>docker-build</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> <execution> <id>docker-push</id> <phase>deploy</phase> <goals> <goal>push</goal> </goals> </execution> </executions> <configuration> <imageName>mydockerimage</imageName> <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <includes> <include>${project.build.finalName}.jar</include> </includes> </resource> </resources> </configuration> </plugin> </plugins> </build> ``` 这个配置告诉Maven Docker插件在打包阶段构建和打标签Docker镜像,并在部署阶段将Docker镜像推送到Docker Registry。 然后,在终端中运行以下命令: ``` mvn clean package docker:build -DskipTests ``` 这将执行以下操作: - 清除Maven目标文件夹。 - 打包Maven项目。 - 使用Maven Docker插件构建Docker镜像。 - 跳过运行测试。 如果需要将Docker镜像推送到Docker Registry,可以运行以下命令: ``` mvn docker:push ``` 这将使用Maven Docker插件将构建好的Docker镜像推送到Docker Registry。 希望这些信息能够对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值