Skip to content

Instantly share code, notes, and snippets.

@LuanComputacao
Last active October 30, 2023 10:47
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save LuanComputacao/6cf199fc577f7ee5fb85a504176d78ca to your computer and use it in GitHub Desktop.
Save LuanComputacao/6cf199fc577f7ee5fb85a504176d78ca to your computer and use it in GitHub Desktop.
Dockerfile to install maven
#
# Oracle Java 7 Dockerfile
#
# https://github.com/dockerfile/java
# https://github.com/dockerfile/java/tree/master/oracle-java7
#
# Pull base image.
FROM alpine as build
ARG MAVEN_VERSION=3.6.3
ARG USER_HOME_DIR="/root"
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
# Install Java.
RUN apk --update --no-cache add openjdk7 curl
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
# Define working directory.
WORKDIR /data
# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/default-jvm/
# Define default command.
CMD ["mvn", "--version"]
# Spring docker sample
# FROM openjdk:8-jdk-alpine
# VOLUME /tmp
# ARG JAR_FILE
# COPY ${JAR_FILE} app.jar
# ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
@Haarolean
Copy link

For the ones not wishing to manually replace maven version in a dockerfile every time a new release is out (since the repo used in this dockerfile deletes the old packages once the new is out), here's my take on automatically downloading the latest stable maven version:
https://gist.github.com/Haarolean/a2a8acf07dfd60cbd68bfdfd20ca9195
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment