- In your Docker Engine configuration, make sure you have
experimental
set totrue
&feature.buildkit
set totrue
- In your
ssh
config, enablessh-agent
forwarding viaForwardAgent yes
- Make sure your
ssh-agent
is running and your private key(s) have been added (quick setup guide)
If you want to make things easier on yourself, you can use keychain to manage your ssh key(s).
- Run
ssh-add -l
. First make sure your key(s) are being loaded (if not, repeat step 3 carefully). Next make sure at least one of the valid indentities matches a valid ssh key linked to your GitHub account. Navigate to SSH and GPG keys in your user settings to see all of your active SSH keys.
- Add the following to any build steps that require your
ssh
permissions:
services:
...
foo:
build:
...
ssh: [default]
- For
alpine
images, add the following to yourDockerfile
:
RUN apk add --update openssh git
RUN echo -e "PermitRootLogin yes" >> /etc/ssh/sshd_config
RUN mkdir -p /root/.ssh \
&& touch /root/.ssh/known_hosts
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
- For any commands that require
ssh
permissions, use the following prefix:
RUN --mount=type=ssh ...
References: