zl程序教程

您现在的位置是:首页 >  工具

当前栏目

maven 上传 docker 到 nexus

2023-09-11 14:21:21 时间

nexus 安装:https://blog.csdn.net/hanjun0612/article/details/105199191

docker destop 安装:https://blog.csdn.net/hanjun0612/article/details/119798564

上面的就不赘述了。

 

一,查看nexus 仓库

假设这个仓库的地址:nexus/java/

用户名:admin

密码:admin

 

二,配置maven

maven 的settings.xml添加

<server>   
    <id>test</id>   
    <username>admin</username>   
    <password>admin</password>   
  </server>  

 

三,pom文件

<plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>1.2.0</version>
                    <configuration>
                        <!--nexus3 hosted 仓库地址-->
                        <registryUrl>nexus/java/</registryUrl>
                        <!--Dockerfile路径,如果你使用dockerfile,就取消注释-->
<!--                        <dockerDirectory>src/main/docker</dockerDirectory>-->
                        <!--是否强制覆盖已有镜像-->
                        <forceTags>true</forceTags>
                        <baseImage>openjdk</baseImage>
                        <!--复制jar包到docker容器指定目录配置-->
                        <resources>
                            <resource>
                                <targetPath>/</targetPath>
                                <directory>${project.build.directory}</directory>
                                <include>${project.build.finalName}.jar</include>
                            </resource>
                        </resources>
                        <!--在maven settings.xml中配置的server的id值-->
                        <serverId>test</serverId>
                    </configuration>
                </plugin>

 

 

dockerfile

自行修改 ADD中的  jar包名

FROM openjdk
VOLUME /tmp
ADD registry-1.0.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
#设置时区
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone

 

最后 maven 运行

#login  nexusip:port  是你的nexus地址和端口
docker login --username=admin --password="admin" nexusip:port

#修改tag名
#其实这里tag是对的,只是需要前缀namespace
#因此打包前,把<imageName>设置为 docker_hosted/imageName:tag 就可以忽略这一步

docker tag imageID nexus的docker_hosted/hello-world:1.0
#上传
docker push nexus的docker_hosted/hello-world:1.0