构建 Docker 时 git clone 身份验证失败

发布于 2025-01-11 04:09:29 字数 2086 浏览 0 评论 0原文

我正在处理 Dockerfile。这是一个带有 ROS 旋律的 Ubuntu 18.04 镜像,我需要在使用 git 构建 Docker 镜像时克隆一些存储库

通常,我会生成一个新的 SSH 密钥并将该密钥添加到我的 GitHub 帐户,但现在情况有所不同,因为要做我通常做的事情,我必须构建 Docker 映像,运行它,然后克隆(&构建)git 存储库。

另外,我将分发此 Docker 映像,但我真的不想使用 SSH 密钥将这些存储库链接到我的帐户。

到目前为止,这是我尝试过的:

# Create a non-root user whom can sudo
RUN useradd -ms /bin/bash -G sudo <username>
RUN echo '<username>:<password>' | chpasswd

# Create a workspace and set WORKDIR
<...>

# Set git defaults
COPY --chown=<username>:<username> .gitconfig /home/<username>
COPY .gitconfig /root

# Clone the git repository
ARG ghname
ARG ghtoken
RUN git clone https://$ghname:[email protected]/<organization>/<repo>.git

这次尝试失败了:

Step 20/30 : Copy --chown=<username>:<username> .gitconfig /home/<username>
COPY failed: file not found in build context or excluded by .dockerignore: stat .gitconfig: file does not exist
...
...
Cloning into '<repo>'...
remote: Repository not found.
fatal: Authentication failed for 'https://:@github.com/<organization>/<repo>.git/'

然后我尝试了:

# Create a non-root user whom can sudo
RUN useradd -ms /bin/bash -G sudo <username>
RUN echo '<username>:<password>' | chpasswd

# Create a workspace and set WORKDIR
<...>

# Clone the git repository
git clone [email protected]:<organization>/<repo>.git

这次尝试失败了(如预期):

Cloning into '<repo>'...
fatal: unable to fork
The command '/bin/sh -c git clone [email protected]:<organization>/<repo>.git' returned a non-zero code: 128

I'm working on a Dockerfile. It's an Ubuntu 18.04 image with ROS melodic, I need to clone a few repositories while building the Docker image using git.

Normally, I'd generate a new SSH key and add that key to my GitHub account but things are different now because to do what I typically do, I'll have to build the Docker image, run it, and then clone (& build) the git repositories.

Also, I will be distributing this Docker image, and I don't really want to link these repositories to my account with an SSH key.

So far this is what I tried:

# Create a non-root user whom can sudo
RUN useradd -ms /bin/bash -G sudo <username>
RUN echo '<username>:<password>' | chpasswd

# Create a workspace and set WORKDIR
<...>

# Set git defaults
COPY --chown=<username>:<username> .gitconfig /home/<username>
COPY .gitconfig /root

# Clone the git repository
ARG ghname
ARG ghtoken
RUN git clone https://$ghname:[email protected]/<organization>/<repo>.git

This attempt failed:

Step 20/30 : Copy --chown=<username>:<username> .gitconfig /home/<username>
COPY failed: file not found in build context or excluded by .dockerignore: stat .gitconfig: file does not exist
...
...
Cloning into '<repo>'...
remote: Repository not found.
fatal: Authentication failed for 'https://:@github.com/<organization>/<repo>.git/'

Then I tried:

# Create a non-root user whom can sudo
RUN useradd -ms /bin/bash -G sudo <username>
RUN echo '<username>:<password>' | chpasswd

# Create a workspace and set WORKDIR
<...>

# Clone the git repository
git clone [email protected]:<organization>/<repo>.git

This attempt failed (as expected):

Cloning into '<repo>'...
fatal: unable to fork
The command '/bin/sh -c git clone [email protected]:<organization>/<repo>.git' returned a non-zero code: 128

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文