Docker: Fetching from Private GitHub Repositories Using "go get"
When attempting to run a container hosting a golang service from a private GitHub repository, you may encounter difficulties if you are using the google/debian:wheezy image as your starting point. This error arises when "go get" attempts to clone the repository.
The issue stems from difficulties in cloning the private repository due to SSH key validation problems. Notably, although you have added the GitHub SSH keys to the Dockerfile to allow cloning, there appears to be an issue with validating the public key.
To resolve this issue, consider the following solution:
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
This solution involves installing SSH and building a private key into the container. While not ideal, it provides a workaround for the issue of fetching private repositories using "go get" in a Docker environment based on Debian Wheezy.
The above is the detailed content of How to Use 'go get' to Fetch from Private GitHub Repositories in a Debian Wheezy Docker Container?. For more information, please follow other related articles on the PHP Chinese website!