"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Use "go get" to Fetch from Private GitHub Repositories in a Debian Wheezy Docker Container?

How to Use "go get" to Fetch from Private GitHub Repositories in a Debian Wheezy Docker Container?

Published on 2024-11-20
Browse:518

How to Use

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:

  1. Install SSH and Configure Git to Use SSH:
RUN apt-get update && apt-get install -y ca-certificates git-core ssh
  1. Add the Private Key to the Container:
ADD keys/my_key_rsa /root/.ssh/id_rsa
  1. Set Permissions on the Private Key:
RUN chmod 700 /root/.ssh/id_rsa
  1. Configure Git to Force SSH for GitHub:
RUN echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config
  1. Set the Git SSH URL Preference:
RUN git config --global url.ssh://[email protected]/.insteadOf https://github.com/
  1. Add the Private Repository to the Docker Image:
ADD . /go/src/github.com/myaccount/myprivaterepo
  1. Execute "go get" and Install the Package:
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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3