Skip to content

Instantly share code, notes, and snippets.

@guillaumerose
Last active July 9, 2018 09:53
Show Gist options
  • Save guillaumerose/dce1ddbac4ada9ee01325e13cb0711bd to your computer and use it in GitHub Desktop.
Save guillaumerose/dce1ddbac4ada9ee01325e13cb0711bd to your computer and use it in GitHub Desktop.
Speedup your Maven builds

With the latest version of Docker for Mac and Windows (18.06), you can prefix all your mvn commands by RUN --mount=target=/root/.m2,type=cache:

Example:

# syntax = tonistiigi/dockerfile:runmount20180618
FROM maven:3.5-jdk-8-alpine AS build
COPY . .
RUN --mount=target=/root/.m2,type=cache mvn --batch-mode clean compile assembly:single

FROM openjdk:8-jre-alpine3.7
EXPOSE 8080
COPY --from=build target/app.jar /app.jar
CMD java -jar /app.jar

Usage:

$ DOCKER_BUILDKIT=1 docker build -t app .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment