title: --mount=type=cache in buildkit
body: <p>I'm trying to get maven offline builds working from within a docker container. I've enabled buildkit. I've run <code>mvn dependency:go-offline -s ~/checkouts/settings.xml</code> to cache the dependencies in <code>/root/.m2</code> of host machine. I wish to use this inside the container that builds maven project.</p>
  
  <p>Here is my Dockerfile:</p>
  
  <pre><code>#syntax=docker/dockerfile:experimental
  FROM maven:3.6.1-jdk-11 AS build
  WORKDIR /
  COPY . /
  RUN --mount=type=cache,target=/root/.m2 mvn -o install 
  
  FROM scratch
  COPY --from=build /admin/admin- 
  rest/target/admin-rest.war /webapps/ROOT.war
  </code></pre>
  
  <p>When I try to <code>docker build</code> this Dockerfile, I get the following error:</p>
  
  <blockquote>
    <p>Plugin org.codehaus.mojo:build-helper-maven-plugin:3.0.0 or one of its
    dependencies could not be resolved: Cannot access central
    (<a href="https://repo.maven.apache.org/maven2" rel="noreferrer">https://repo.maven.apache.org/maven2</a>) in offline mode and the
    artifact org.codehaus.mojo:build-helper-maven-plugin:jar:3.0.0 has not
    been downloaded from it before. -> [Help 1]</p>
  </blockquote>
  
  <p>My Docker version:</p>
  
  <pre><code>Client:
   Version:           18.09.6
   API version:       1.39
   Go version:        go1.10.8
   Git commit:        481bc77
   Built:             Sat May  4 02:35:57 2019
   OS/Arch:           linux/amd64
   Experimental:      false
  
  Server: Docker Engine - Community
   Engine:
    Version:          19.03.1
    API version:      1.40 (minimum version 1.12)
    Go version:       go1.12.5
    Git commit:       74b1e89
    Built:            Thu Jul 25 21:19:41 2019
    OS/Arch:          linux/amd64
    Experimental:     false
   containerd:
    Version:          1.2.5
    GitCommit:        bb71b10fd8f58240ca47fbb579b9d1028eea7c84
   runc:
    Version:          1.0.0-rc6+dev
    GitCommit:        2b18fe1d885ee5083ef9f0838fee39b62d653e30
   docker-init:
    Version:          0.18.0
    GitCommit:        fec3683
  </code></pre>
  
  <p>Am I right in my expectation that <code>/root/.m2</code> from my host machine needs to get mounted on to <code>/root/.m2</code> inside the docker container environment? And when I run <code>mvn -o install</code> it needs to refer to the mounted <code>/root/.m2</code>?</p>
  
  <p>I added <code>tail -f /dev/null</code>, removed second build stage and changed the <code>mvn install</code> to <code>mvn version</code> with the cache-mount instruction intact in order to debug this. I see that nothing gets mounted on to /root/.m2 inside the container. It is empty.  (Unsure if this is the right way to debug this as it may get unmounted after the image is built)</p>