Home > Backend Development > Golang > How to Retrieve Code from a Private GitHub Repository in Docker?

How to Retrieve Code from a Private GitHub Repository in Docker?

Linda Hamilton
Release: 2024-11-09 10:14:02
Original
376 people have browsed it

How to Retrieve Code from a Private GitHub Repository in Docker?

Docker: Retrieving Code from a Private GitHub Repository

Encountering difficulties while retrieving code from a private GitHub repository during Docker container execution? This problem manifests with an error indicating a failure to read the username for 'https://github.com'.

To address this issue, it's necessary to augment the Dockerfile with a series of steps:

  1. Install SSH and required certificates.
  2. Add the private key to the container's file system.
  3. Configure Git to use SSH instead of HTTPS.
  4. Retrieve the code from the private repository using go get.

Here's a modified Dockerfile that incorporates these steps:

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

With this modified Dockerfile, you can now retrieve code from a private GitHub repository during container execution.

The above is the detailed content of How to Retrieve Code from a Private GitHub Repository in Docker?. 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