2

Still new to Docker and trying to get a Jetty webservice to run inside a container. This is my docker file at the moment

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.

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

My project structure is like so

Project structure service

  • api
  • lib
  • webapp
  • pom.xml

Error

The following artifacts could not be resolved: 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?

tomaytotomato
  • 3,788
  • 16
  • 64
  • 119
  • Possible duplicate of [Do not download all Maven dependencies on a Docker build](http://stackoverflow.com/questions/38293073/do-not-download-all-maven-dependencies-on-a-docker-build) – nwinkler Nov 03 '16 at 12:20
  • Potentially also of interest: http://stackoverflow.com/questions/39977955/how-to-mount-docker-volume-into-my-docker-project-using-compose – nwinkler Nov 03 '16 at 12:21
  • Those are not useful because I want to download dependencies during docker build but I don't want to repeat the same process at Docker run – tomaytotomato Nov 03 '16 at 12:47

1 Answers1

4

SNAPSHOT dependencies are checked for updates regularly by Maven - by default on a daily basis. But you can disable this in your settings.xml of Maven. 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).

Example Repository setting in your settings.xml:

<repository>
    <id>snapshots</id>
    <url>http://host/nexus/repos/snapshots</url>
    <snapshots>
        <updatePolicy>never</updatePolicy>
    </snapshots>
    <releases>
        <updatePolicy>never</updatePolicy>
    </releases>
</repository>
Community
  • 1
  • 1
Florian Albrecht
  • 2,266
  • 1
  • 20
  • 25