I'm trying to write a Dockerfile that pulls a private repository from github. The problem is that I can't get Docker buildkit to use my SSH key properly. Even using the precise instructions and example code from their website does not work. Here is what I did:
- Created a passphraseless SSH key using
ssh-keygen -t ed25519 -C my_email@my_company.com
- Copied the public key and added it as a Github deploy key to my repository
ssh-add
ed the key- Ran the Dockerfile
# syntax=docker/dockerfile:1
FROM alpine
# Install ssh client and git
RUN apk add --no-cache openssh-client git
# Download public key for github.com
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
# Clone private repository
RUN --mount=type=ssh git clone git@github.com:myorg/myproject.git myproject
replacing myproject
and myorg
appropriately. Copy-pasting the git clone
command from the Dockerfile to the terminal works. Running DOCKER_BUILDKIT=1 docker build --ssh default
and DOCKER_BUILDKIT=1 docker build --ssh default=/path/to/key
both fail with the error
> [4/4] RUN --mount=type=ssh git clone git@github.com/myorg/myrepository.git myrepository
#9 0.262 fatal: repository 'git@github.com/myorg/myrepository.git' does not exist
What could be going on here? I'm using Docker 20.10.12 build e91ed57 on MacOS 10.14.6.