Skip to content

Instantly share code, notes, and snippets.

@dkirrane
Forked from guillaumerose/README.md
Created July 9, 2018 09:53
Show Gist options
  • Save dkirrane/1750e73b7e6f71d35ba82ddeeddd2ef7 to your computer and use it in GitHub Desktop.
Save dkirrane/1750e73b7e6f71d35ba82ddeeddd2ef7 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