Home > Backend Development > Golang > How to Access Private GitHub Repositories in Docker Containers?

How to Access Private GitHub Repositories in Docker Containers?

Susan Sarandon
Release: 2024-11-09 12:41:01
Original
845 people have browsed it

How to Access Private GitHub Repositories in Docker Containers?

Docker: Fetching from Private GitHub Repositories

Question:

When attempting to utilize a private GitHub repository within a Docker container to expose a Go service, an error occurs during the go get process, citing a problem with the public key validation. How can this issue be resolved?

Answer:

1. Ensure Proper SSH Key Permissions:

  • Verify that the private and public SSH keys added to the Dockerfile (priv/id_rsa and priv/id_rsa.pub) have appropriate permissions (e.g., chmod 600 or chmod 700).

2. Force SSH Usage for Git Operations:

  • Add the following line to the Dockerfile: RUN git config --global url.ssh://[email protected]/.insteadOf https://github.com/, forcing git to use SSH instead of HTTPS.

3. Example Dockerfile:

FROM golang

RUN apt-get update && apt-get install -y ca-certificates git-core ssh

ADD keys/my_key_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config
RUN git config --global url.ssh://[email protected]/.insteadOf https://github.com/

ADD . /go/src/github.com/myaccount/myprivaterepo

RUN go get github.com/myaccount/myprivaterepo
RUN go install github.com/myaccount/myprivaterepo
Copy after login

This modified Dockerfile includes SSH configuration and forces the use of SSH for Git operations, resolving the issue encountered during the go get process.

The above is the detailed content of How to Access Private GitHub Repositories in Docker Containers?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template