Docker image with Maven fails to run

I want to use Maven in my Docker image.

After looking here, I tried using this Dockerfile:

  • How do I mount a host directory as a volume in docker compose
  • Port Publishing When Running with Docker Compose
  • Validating docker-compose yml file
  • Docker download Google's TensorFlow issue
  • Possible to run two instances of docker containers on one mysql database container?
  • Many Docker Containers and Thrift
  • FROM openjdk:7
    RUN apk add --no-cache curl tar bash
    ARG USER_HOME_DIR="/root"
    RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
      && curl -fsSL$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz \
        | tar -xzC /usr/share/maven --strip-components=1 \
      && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
    ENV MAVEN_HOME /usr/share/maven
    COPY /usr/local/bin/
    COPY settings-docker.xml /usr/share/maven/ref/
    ENTRYPOINT ["/usr/local/bin/"]
    CMD ["mvn"]

    However, I’m getting:

    lstat no such file or directory

    I tried different Dockerfiles from the same repositories but they all throw this error.

    What’s wrong with this dockerfile?
    How can I use Maven with Docker?

  • Building CPU usage graph in Grafana for Docker container
  • Dockerfile can't find
  • Run image in docker
  • docker-compose wordpress mysql connection refused
  • Run a docker with specific ip address
  • Docker error: too many open files
  • 3 Solutions collect form web for “Docker image with Maven fails to run”

    Try this:


    FROM openjdk:8u111-jdk-alpine
    COPY assets/settings.xml /tmp/settings.xml
    ENV PATH=$PATH:/opt/maven/bin
    RUN apk add --no-cache curl tar bash && \
      curl -SsL -o /tmp/maven.tar.gz && \
      mkdir -p /opt && \
      tar xzf /tmp/maven.tar.gz -C /opt/ && \
      ln -s /opt/apache-maven-3.3.9 /opt/maven && \
      rm /tmp/maven.tar.gz && \
      mv /tmp/settings.xml /opt/maven/conf/settings.xml

    You need to put this Dockerfile in a new directory, with a subdirectory called ‘assets’, and you need to put a maven settings file (settings.xml) in that directory. If you don’t have a custom settings file then remove the COPY and the mv.

    Build it with something like

    docker --tag ajava8 .

    You can run maven in your current directory using something like:

    docker run -it --rm -v /$PWD:/work -w /work ajava8 mvn clean install

    Or, you can get a bash shell with something similar, like this:

    docker run -it --rm -v /$PWD:/work -w /work ajava8 bash

    I just ran into the same problem, I have forgotten to download the “” file.. .. also the settings-docker.xml was required..

    You need the files copied in the Dockerfile and settings-docker.xml.
    You can git clone from

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