Docker image with Maven fails to run

I want to use Maven in my Docker image.

After looking here https://hub.docker.com/_/maven/, I tried using this Dockerfile:

  • “docker-compose up” fails with error
  • Docker setup - facing issues while running chaincode locally
  • Forbid docker to use specific network
  • Modifying a docker image
  • How to use SERVICE_CHECK_HTTP with progrium/consul check-http script?
  • Docker on CentOS 7.2: kernel:unregister_netdevice: waiting for lo to become free. Usage count = 1
  • FROM openjdk:7
    
    RUN apk add --no-cache curl tar bash
    
    ARG MAVEN_VERSION=3.3.9
    ARG USER_HOME_DIR="/root"
    
    RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
      && curl -fsSL http://apache.osuosl.org/maven/maven-3/$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
    ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
    
    COPY mvn-entrypoint.sh /usr/local/bin/mvn-entrypoint.sh
    COPY settings-docker.xml /usr/share/maven/ref/
    
    VOLUME "$USER_HOME_DIR/.m2"
    
    ENTRYPOINT ["/usr/local/bin/mvn-entrypoint.sh"]
    CMD ["mvn"]
    

    However, I’m getting:

    lstat mvn-entrypoint.sh: 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?

  • How to upgrade elasticbeanstalk docker version
  • How to allocate more memory for docker container?
  • Docker run command failing when trying to install the mysql php extension
  • docker non-root bind-mount permissions, WITH --userns-remap
  • creating a default database in mysql using dockerfile
  • How to use docker to create a minimal live ISO that runs docker?
  • 3 Solutions collect form web for “Docker image with Maven fails to run”

    Try this:

    Dockerfile:-

    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 http://www-us.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.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 “mvn-entrypoint.sh” file.. https://github.com/carlossg/docker-maven/tree/322d0dff5d0531ccaf47bf49338cb3e294fd66c8/jdk-8 .. also the settings-docker.xml was required..

    You need the files copied in the Dockerfile mvn-entrypoint.sh and settings-docker.xml.
    You can git clone from https://github.com/carlossg/docker-maven

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