Docker --ssh default Permission denied (publickey)

Viewed 2182

I am trying to build a docker image with --ssh default on MacOS but it is not working. The same build work on Linux.

//Dockerfile

#syntax=docker/dockerfile:experimental
FROM node:16

WORKDIR /app

RUN chown -R node.node /app

RUN mkdir ~/.ssh/ && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

RUN --mount=type=ssh git clone git+ssh://git@github.com/account_name/repo.git

CMD tail -f /dev/null

When I run

docker build --ssh default -t my_image .

I get the error:

git@github.com: Permission denied (publickey)
fatal: Could not read from remote repository

I have my ssh key in ~/.ssh/id_rsa on my local machine and it is working outside docker.

If I try to run in the Dockerfile:

RUN --mount=type=ssh cat ~/.ssh/id_rsa

I get the error:

cat: /root/.ssh/id_rsa No such file or directory
1 Answers
Related