title: Docker: using SSH in builds with Buildkit
body: <p>Following the <a href="https://docs.docker.com/develop/develop-images/build_enhancements/#using-ssh-to-access-private-data-in-builds" rel="nofollow noreferrer">documentation</a> I'm trying to pass an SSH key to my container. This is my original Dockerfile</p>
  <pre><code># syntax=docker/dockerfile:experimental
  FROM tiangolo/uvicorn-gunicorn-fastapi:python3.6
  
  RUN mkdir -p -m 0600 ~/.ssh &amp;&amp; ssh-keyscan github.com &gt;&gt; ~/.ssh/known_hosts
  
  RUN --mount=type=ssh git clone git@github.com:USER/REPO.git
  </code></pre>
  <p>and this works</p>
  <p><code>DOCKER_BUILDKIT=1 docker build --ssh default=~/github .</code></p>
  <p>However, if I try to install anything with apt:</p>
  <pre><code># syntax=docker/dockerfile:experimental
  FROM tiangolo/uvicorn-gunicorn-fastapi:python3.6
  
  RUN apt update
  
  RUN mkdir -p -m 0600 ~/.ssh &amp;&amp; ssh-keyscan github.com &gt;&gt; ~/.ssh/known_hosts
  
  RUN --mount=type=ssh git clone git@github.com:USER/REPO.git
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>[+] Building 1.8s (7/9)
   =&gt; [internal] load .dockerignore                                                                                                                                                                                                       0.0s
   =&gt; =&gt; transferring context: 2B                                                                                                                                                                                                         0.0s
   =&gt; [internal] load build definition from Dockerfile                                                                                                                                                                                    0.0s
   =&gt; =&gt; transferring dockerfile: 306B                                                                                                                                                                                                    0.0s
   =&gt; resolve image config for docker.io/docker/dockerfile:experimental                                                                                                                                                                   1.1s
   =&gt; CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:de85b2f3a3e8a2f7fe48e8e84a65f6fdd5cd5183afa6412fff9caa6871649c44                                                                                              0.0s
   =&gt; [internal] load metadata for docker.io/tiangolo/uvicorn-gunicorn-fastapi:python3.6                                                                                                                                                  0.0s
   =&gt; CACHED [1/4] FROM docker.io/tiangolo/uvicorn-gunicorn-fastapi:python3.6                                                                                                                                                             0.0s
   =&gt; ERROR [2/4] RUN apt update                                                                                                                                                                                                          0.4s
  ------
   &gt; [2/4] RUN apt update:
  #7 0.352
  #7 0.352 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
  #7 0.352
  #7 0.359 Reading package lists...
  #7 0.375 E: Could not get lock /var/lib/apt/lists/lock - open (13: Permission denied)
  #7 0.375 E: Unable to lock directory /var/lib/apt/lists/
  ------
  failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to build LLB: executor failed running [/bin/sh -c apt update]: runc did not terminate sucessfully
  </code></pre>
  <p>However, the second Dockerfile actually works if Buildkit is disabled. Any suggestions on what might be the problem?</p>