Skip to content

Instantly share code, notes, and snippets.

@nballenger
Created January 30, 2020 20:29
Show Gist options
  • Save nballenger/0b696299ee32b735d940b21ebb8e71d3 to your computer and use it in GitHub Desktop.
Save nballenger/0b696299ee32b735d940b21ebb8e71d3 to your computer and use it in GitHub Desktop.
private-git-in-container-build
Host github.com
Hostname github.com
User git
IdentityFile ~/.ssh/inside-docker-container
# syntax=docker/dockerfile:experimental
FROM centos:centos7 AS base
RUN yum -y updateinfo \
&& yum -y install git
RUN mkdir -p -m 0600 ~/.ssh \
&& ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh git clone git@github.com:nballenger/fictional-goggles.git
echo "create a new ssh key"
ssh-keygen -t rsa -b 4096 -C "you@your.domain.tld" -f ~/.ssh/inside-docker-container
echo "Copy ~/.ssh/inside-docker-container.pub into github as a new ssh key"
echo "Add the key file to your ssh agent"
ssh-add ~/.ssh/inside-docker-container
echo "Create the .ssh/config entry and the Dockerfile"
echo "cd to the Dockerfile's enclosing folder"
echo "build, with buildkit enabled by flag, so you get the --ssh option"
DOCKER_BUILDKIT=1 docker build -t centos-git --ssh default .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment