简体   繁体   English

Docker:仅在构建阶段安装Maven依赖项?

[英]Docker : Install Maven dependencies during build stage only?

Still new to Docker and trying to get a Jetty webservice to run inside a container. 对于Docker来说仍然是新手,它试图让Jetty Web服务在容器中运行。 This is my docker file at the moment 这是我目前的docker文件

Recipe 食谱

FROM maven:3.3-jdk-8-alpine

# Install packages
# To find packages to install see - https://pkgs.alpinelinux.org/packages
RUN apk add --no-cache curl tar bash wget apache-ant
RUN apk info

# Do any Maven configuration
ENV MAVEN_HOME /usr/share/maven
VOLUME "$USER_HOME_DIR/.m2"
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"


# Copy over project source files to the /tmp folder
COPY . /tmp/project
WORKDIR /tmp/project

# Preinstall any Maven depencencies
RUN mvn install -pl '!deb' -DskipTests

# Default command when running the docker image, can be overriden
CMD cd webapp/ && mvn jetty:run

During the docker build I specify maven install to install all dependencies for the project and build the jars for each module from sources. 在docker构建期间,我指定maven install来安装项目的所有依赖项,并从源代码构建每个模块的jar。

However when then run the docker container, it still tries to reinstall all the dependencies and then fails because it cannot find my api.jar file 但是,当然后运行docker容器时,它仍然尝试重新安装所有依赖项,然后失败,因为它找不到我的api.jar文件

My project structure is like so 我的项目结构是这样的

Project structure service 项目结构服务

  • api api
  • lib LIB
  • webapp 网络应用
  • pom.xml pom.xml

Error 错误

The following artifacts could not be resolved: com.foo.service:service-api:jar:1.14-SNAPSHOT 无法解决以下工件:com.foo.service:service-api:jar:1.14-SNAPSHOT

Doing the same steps outside of a container works fine and the jetty service starts ok. 在容器外部执行相同的步骤可以正常工作,并且码头服务开始正常。 Any ideas how to fix? 任何想法如何解决?

SNAPSHOT dependencies are checked for updates regularly by Maven - by default on a daily basis. Maven会定期检查SNAPSHOT依赖项是否有更新-默认情况下每天进行更新。 But you can disable this in your settings.xml of Maven. 但是您可以在Maven的settings.xml中禁用它。 See https://stackoverflow.com/a/3942048/2235015 for an answer in a similar (but inverted) case, and see http://maven.apache.org/ref/3.2.2/maven-settings/settings.html (search for updatePolicy ). 参见https://stackoverflow.com/a/3942048/2235015 ,以获取类似(但倒置)情况下的答案,并参见http://maven.apache.org/ref/3.2.2/maven-settings/settings。 html (搜索updatePolicy )。

Example Repository setting in your settings.xml : settings.xml示例存储库settings.xml

<repository>
    <id>snapshots</id>
    <url>http://host/nexus/repos/snapshots</url>
    <snapshots>
        <updatePolicy>never</updatePolicy>
    </snapshots>
    <releases>
        <updatePolicy>never</updatePolicy>
    </releases>
</repository>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM