How to Resolve 'fatal: could not read Username for 'https://github.com': No such device or address' Error When Cloning Private GitHub Repos in Docker?

Barbara Streisand
Release: 2024-11-16 13:26:03
Original
898 people have browsed it

How to Resolve

Docker: Resolving GitHub SSH Key Issues for Private Repo Cloning

When attempting to run a container that utilizes a golang service from a private GitHub repository, you may encounter errors during the go get process. One such error is related to problems reading the GitHub SSH public key.

Problem:
When running go get github.com// within a Dockerfile, the process fails with the error: "fatal: could not read Username for 'https://github.com': No such device or address."

Cause:
This error indicates that the Dockerfile is not properly configured to authenticate with GitHub using SSH. The ssh-keyscan command reveals a mismatch between the public key and the remote host's record.

Solution:
To resolve this issue, you need to add a git config command to your Dockerfile that forces the use of SSH instead of the default HTTPS protocol for GitHub cloning. Here's an example Dockerfile that incorporates this fix:

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://git@github.com/.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 revised Dockerfile ensures that SSH is used for GitHub cloning, addressing the error related to reading the public key. It also includes the necessary steps to install SSH and configure the identity key.

The above is the detailed content of How to Resolve 'fatal: could not read Username for 'https://github.com': No such device or address' Error When Cloning Private GitHub Repos 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