使用 Docker 构建阶段中的本地 m2 仓库

huangapple go评论85阅读模式
英文:

Use local m2 repository in docker build stage

问题

I made a Java project which uses an own library, which is installed in my local m2 repository. Now, I'm trying to create a Docker image that generates the jar in a build stage. It fails because it can't resolve dependencies for project of my own library. Is there any way to tell maven (from container) to use my local m2 repository (outside container) so it could resolve my library dependency when I run mvn package?

英文:

I made a Java project which uses an own library, which is installed in my local m2 repository. Now, I'm trying to create a Docker image that generates the jar in a build stage. It fails because it can't resolve dependencies for project of my own library. Is there any way to tell maven (from container) to use my local m2 repository (outside container) so it could resolve my library dependency when I run mvn package?

答案1

得分: 3

简单回答 - 无法通过docker build命令挂载卷,因为没有办法进行卷挂载。

我假设您的最终目标是创建一个包含项目构建的jar或war文件的Docker镜像。

要实现这一目标,您需要两个Dockerfile - 一个用于创建一个容器,该容器将构建您的项目并退出;第二个描述实际所需的镜像 - 一个用于创建运行您的项目的容器。

有一篇很好的文章描述了如何创建和使用第一个Dockerfile,请点击此处查看。至于第二个Dockerfile,这取决于您的项目是构建为jar还是war文件,以及它如何需要启动/部署。

英文:

Simple answer - you can't, because there is no way to mount a volume for docker build command.

I'm assuming your end goal is a Docker image that runs contains your project's built jar or war.

To accomplish that you need two Dockerfiles - one that can be used to create a container that will build your project and exit and a second one that will describe the image that you actually want - one that can be used to create a container that runs your project.

There is a nice article describing how to create and use the first one here. As
for the second one, that depends on whether your project builds as jar or a war and how it needs to be started/deployed.

答案2

得分: 1

有两种管理库(包括私有库)的方法:

  1. (旧方式)将编译好的库复制到项目的库目录中,并确保项目能够识别它。

  2. 使用一些仓库管理软件。良好的选择包括 - Artifactory https://jfrog.com/artifactory 或 Nexus 仓库管理 - https://www.sonatype.com/product-nexus-repository

英文:

There is two ways of managing libraries (including private):

  1. (old way) copy your compiled library to your project lib directory and make sure your project pick it up.

  2. use some repository management software. Good options is - Artifactory https://jfrog.com/artifactory or Nexus repository management - https://www.sonatype.com/product-nexus-repository

huangapple
  • 本文由 发表于 2020年8月16日 13:06:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63433361.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定