Brian Corbin
Brian Corbin

Reputation: 267

How do you set an ssh key for docker image containing a private git repo?

I'm trying to get a docker image to build that requires it to clone a private github repo.

Upvotes: 0

Views: 378

Answers (1)

Logan Shire
Logan Shire

Reputation: 5103

I had a hard time figuring out how to do this without copying my ssh keys over - my eventual solution was to use a github basic auth token in URL format passed into docker as a build argument.

In Dockerfile

ARG GITHUB_URL RUN git config --global url.$GITHUB_URL.insteadOf "https://github.com/"

RUN go get -u github.com/YOUR_USERNAME/YOUR_REPO

When Building

docker build -t YOUR_TAG . --build-arg GITHUB_URL="https://[YOUR_GITHUB_TOKEN]:[email protected]/"

Upvotes: 1

Related Questions