title: docker build command using ssh url to git repo: Permission denied
body: <p>I'm trying to make a script that will build a bunch of docker images and push them to a private repository.</p>
  <p>From the <a href="https://docs.docker.com/engine/reference/commandline/build/#git-repositories" rel="nofollow noreferrer">documentation</a>, the <code>docker build</code> command seems to accept git urls: very nice indeed.</p>
  <p>All the repos are private and everyone in the company have ssh keys setup to access the git repos via ssh like <code>git clone git@github.com:/my-org/my-repo.git</code></p>
  <p>I assumed that providing such url would work as well as it seems to be a very common use case. Turns out it doesn't.</p>
  <p>I googled around for a solution and found a <a href="https://github.com/moby/moby/issues/29919#issuecomment-270919106" rel="nofollow noreferrer">git ticket about url formatting</a> so I tried all the following:</p>
  <ul>
  <li><code>ssh://git@github.com:/my-org/my-repo.git</code></li>
  <li><code>ssh://git@github.com/my-org/my-repo.git</code></li>
  <li><code>ssh://git@github.com:my-org/my-repo.git</code></li>
  <li><code>git@github.com:/my-org/my-repo.git</code></li>
  <li><code>git@github.com/my-org/my-repo.git</code></li>
  <li><code>git@github.com:my-org/my-repo.git</code></li>
  </ul>
  <p>Th last one in this list is the most promising as I'm getting the following output:</p>
  <pre><code>$ docker build -t registry.example.com:5000/my-repo:latest --ssh=default git@github.com:my-org/my-repo.git
  
  [+] Building 0.9s (1/1) FINISHED                                                                                                                                                             
   =&gt; ERROR [internal] load git source git@github.com:my-org/my-repo.git                                                                                                     0.9s
  ------                                                                                                                                                                                       
   &gt; [internal] load git source git@github.com:my-org/my-repo.git:                                                                                                                
  #1 0.551 Warning: Permanently added the RSA host key for IP address '140.82.121.3' to the list of known hosts.
  #1 0.896 git@github.com: Permission denied (publickey).
  #1 0.898 fatal: Could not read from remote repository.
  #1 0.898 
  #1 0.898 Please make sure you have the correct access rights
  #1 0.898 and the repository exists.
  ------
  failed to solve with frontend dockerfile.v0: failed to read dockerfile: failed to load cache key: failed to fetch remote git@github.com:my-org/my-repo.git: exit status 128
  </code></pre>
  <p>Before someone asks: yes the repo exists and I can clone it :)</p>
  <p>I was assuming the &quot;cloning&quot; part of the process would be done &quot;locally&quot; using my own ssh keys before sending the context out for docker to build. Apparently it is not the case.</p>
  <p>Is it a supported feature and if so how to make it work?</p>
  <hr />
  <p>EDIT: I realised I forgot to give some context.</p>
  <p>I'm running Docker Desktop on macOS big sur</p>
  <p><code>Docker version 20.10.8, build 3967b7d</code></p>
  <pre><code>Client:
   Context:    default
   Debug Mode: false
   Plugins:
    buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
    compose: Docker Compose (Docker Inc., v2.0.0-rc.3)
    scan: Docker Scan (Docker Inc., v0.8.0)
  
  Server:
   Containers: 9
    Running: 8
    Paused: 0
    Stopped: 1
   Images: 28
   Server Version: 20.10.8
   Storage Driver: overlay2
    Backing Filesystem: extfs
    Supports d_type: true
    Native Overlay Diff: true
    userxattr: false
   Logging Driver: json-file
   Cgroup Driver: cgroupfs
   Cgroup Version: 1
   Plugins:
    Volume: local
    Network: bridge host ipvlan macvlan null overlay
    Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
   Swarm: inactive
   Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
   Default Runtime: runc
   Init Binary: docker-init
   containerd version: e25210fe30a0a703442421b0f60afac609f950a3
   runc version: v1.0.1-0-g4144b63
   init version: de40ad0
   Security Options:
    seccomp
     Profile: default
   Kernel Version: 5.10.47-linuxkit
   Operating System: Docker Desktop
   OSType: linux
   Architecture: x86_64
   CPUs: 4
   Total Memory: 3.842GiB
   Name: docker-desktop
   ID: 77LC:Z2AY:K6AA:OXAY:3JYQ:RSSL:RCJZ:GOSK:FUTG:DAPY:WIKK:BB7A
   Docker Root Dir: /var/lib/docker
   Debug Mode: true
    File Descriptors: 105
    Goroutines: 93
    System Time: 2021-09-16T08:47:27.924652162Z
    EventsListeners: 4
   HTTP Proxy: http.docker.internal:3128
   HTTPS Proxy: http.docker.internal:3128
   Registry: https://index.docker.io/v1/
   Labels:
   Experimental: false
   Insecure Registries:
    &lt;REDACTED&gt;
   Live Restore Enabled: false
  </code></pre>