Skip to content

Instantly share code, notes, and snippets.

@samc
Created May 17, 2023 20:12
Show Gist options
  • Save samc/92f7b65b06ad2eed5c5b97ddf9c751ec to your computer and use it in GitHub Desktop.
Save samc/92f7b65b06ad2eed5c5b97ddf9c751ec to your computer and use it in GitHub Desktop.

Pre-requisites (Docker for MacOS / Windows):

  1. In your Docker Engine configuration, make sure you have experimental set to true & feature.buildkit set to true

Screenshot 2023-05-17 at 3 42 48 PM

  1. In your ssh config, enable ssh-agent forwarding via ForwardAgent yes
  2. 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).

  1. 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.

Setting up Docker Compose:

  1. Add the following to any build steps that require your ssh permissions:
services:
  ...
  foo:
    build:
      ...
      ssh: [default]
  1. For alpine images, add the following to your Dockerfile:
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
  1. For any commands that require ssh permissions, use the following prefix:
RUN --mount=type=ssh ...

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment