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