Home > Backend Development > Golang > 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?

DDD
Release: 2024-11-08 17:28:02
Original
655 people have browsed it

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

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template