Docker : Install Maven dependencies during build stage only?

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


  • Docker Like DB Deployment
  • Mongodb container's data becomes “read-only” after restarting kubernetes, with glusterfs as storage?
  • Mounting local volumes to remote docker container, Possible?
  • How to access current directory with Boot2Docker and Docker?
  • Unable to connect to Elasticsearch with PHP inside Docker
  • Update Docker container after making changes to image
  • FROM maven:3.3-jdk-8-alpine
    # Install packages
    # To find packages to install see -
    RUN apk add --no-cache curl tar bash wget apache-ant
    RUN apk info
    # Do any Maven configuration
    ENV MAVEN_HOME /usr/share/maven
    # 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

    • api
    • lib
    • webapp
    • pom.xml


    The following artifacts could not be resolved:

    Doing the same steps outside of a container works fine and the jetty service starts ok. Any ideas how to fix?

  • Nginx and Node.js - Utilizing server to fullest
  • How is it possible to extend docker php image with nodejs?
  • Fetching AWS instance metadata from within Docker container?
  • Node.js tcp sockets + linked Docker containers
  • 404 error when Accessing from local host : NGINX uWSGI
  • Docker containers- running new java8 code on old java6 version
  • One Solution collect form web for “Docker : Install Maven dependencies during build stage only?”

    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 for an answer in a similar (but inverted) case, and see (search for updatePolicy).

    Example Repository setting in your settings.xml:

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.