How to use docker-compose build: ssh: functionality to check out git repositories without persistent ssh keys

I see there was a proposal for new ssh injection code so we can use SSH keys without writing to the file system (and storing it in layers). I see two PRs. How do I use such functionality? I have this in my docker-compose yaml file:

      dockerfile: Dockerfile
      ssh:                    # New functionality in PRs
        - default

What do I put in my Dockerfile? I have code to checkout like this:

ADD /app

However, when I do a docker-compose I get

0.487 fatal: could not read Username for '': terminal prompts disabled

I assume I have to set some environment variable or pass this ssh key to the ADD command somehow. I do have this variable exported in my environment on my Mac:


First of all SSH keys and SSH agent will not help you with HTTPS. That will require password if the repo is not public. If you want to use SSH based git clone, I’m not sure if that works with the ADD instruction at all. Probably not as I have never heard of anything like that. You need git command during the build and use git clone to download the project using an url that works with SSH. ON github, you can choose between HTTP and SSH when you copy the clone url.

And since you added the default SSH agent, that agent should run and you need to add the SSH keys to the agent. Or the other way is not using the agent but the SSH key itself. More details and examples in the documentation:

Also make sure you are using Docker Compose v2 which is usually used as docker compose not docker-compose unless there is an alias.

Sorry. My brain was in neutral when I mentioned HTTPS above. I’ve set up ssh checkout from Github and that seems to work. I think it works with the ADD command but I can’t check because the the current versions of Docker with ADD don’t work for me on my M2 Mac. I am having a lot of problems with them. Older versions (like ancient 4.7.0 work fine).

The newer versions don’t seem to run the images from docker-compose when I select up. The older versions seem to. Do you know why?

There is a command called docker-compose. From my Mac:

1005 ~% ls -l /usr/local/bin/docker-compose
lrwxr-xr-x@ 1 root  wheel  62 Aug 17 21:24 /usr/local/bin/docker-compose -> /Applications/
1006 ~% ls -lc /Applications/
total 453912
-rwxr-xr-x@  1 Scott  admin  48323376 Aug 20 18:57 com.docker.cli
-rwxr-xr-x@  1 Scott  admin  21145024 Aug 20 18:57 com.docker.vpnkit
-rwxr-xr-x@  1 Scott  admin  68573168 Aug 20 18:57 docker
-rwxr-xr-x@  1 Scott  admin   6658448 Aug 20 18:57 docker-compose
drwxr-xr-x@ 75 Scott  admin      2400 Aug 20 18:57 docker-compose-v1
-rwxr-xr-x@  1 Scott  admin   9564992 Aug 20 18:57 docker-credential-desktop
-rwxr-xr-x@  1 Scott  admin   8891712 Aug 20 18:57 docker-credential-ecr-login
-rwxr-xr-x@  1 Scott  admin   2672576 Aug 20 18:57 docker-credential-osxkeychain
-rwxr-xr-x@  1 Scott  admin  14185232 Aug 20 18:57 hub-tool
-rwxr-xr-x@  1 Scott  admin  52368800 Aug 20 18:57 kubectl
1007 ~%

So docker-compose and docker compose aren’t the same thing?

It looks like you are right:

That had a much older Docker Engine. I realized you are using Docker Desktop. Please, always start your posts with sharing what platform you are using Docker on. I could have suspected it since the SSH auth socket contained “apple” in the path, but I didn’t notice it.

So Docker (Docker Engine or Docker CE) and Docker Desktop is not the same thing either. What you are trying to do should work on Mac, but I have never tried it and not everything works on Docker Desktop even though it adds features for developers that Docker CE doesn’t have.

It could be and it probably is on Mac. Docker Compose v1 is not supported anymore but older Docker Desktop had an option to use docker-compose command as an alias to docker-compose-v1 or docker compose. Docker Compose v2 is a CLI plugin. That is why you can use it as docker composethe same way as you could usedocker buildx`.

Makes sense. Thanks for clarification. I see why Docker Desktop (virtual machine) is necessary on my Mac which contains an M2 processor which obviously won’t understand Intel instructions. I can’t run the current version of Docker on my Mac because it is broken.

No it is not because ARM vs AMD64. Virtual machines still use the same architecture. If you want ARM on an AMD64 CPU, that requires emulation. Docker Desktop has that too, but it runs in the virtual machine.

VMs are required because Linux containers can run only on Linux. This is because they are isolated processes not compatible with other operating systems. It is true for every OS. The difference is that Windows can run native Windows containers but macOS doesn’t have container support at all.