构建 Docker 时 git clone 身份验证失败
我正在处理 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论