【问题标题】:How to expose private git repo during docker build without including ssh key in image如何在 docker build 期间公开私有 git repo 而无需在图像中包含 ssh 密钥
【发布时间】:2022-11-18 04:10:26
【问题描述】:

我正在尝试使用 ADD 命令在 docker 构建过程中公开私有 git LFS 存储库,但我不断收到错误消息:

------
> git://192.168.189.143/REPO/my-libs.git:
#37 0.761 Permission denied, please try again.
#37 0.819 Permission denied, please try again.
#37 0.883 git@192.168.189.143: Permission denied (publickey,password).
#37 0.885 fatal: Could not read from remote repository.
#37 0.885 
#37 0.885 Please make sure you have the correct access rights
#37 0.885 and the repository exists.
------
failed to load cache key: failed to fetch remote git@192.168.189.143:REPO/my-libs.git: exit status 128

这是对命令的引用:

我的 docker 文件如下所示:

# syntax=docker/dockerfile-upstream:master-labs
FROM ubuntu:18.04
ENV USER=markf78
USER ${USER}
WORKDIR /home/${USER}/temp
ADD git@192.168.189.143:REPO/my-libs.git /home/${USER}/temp

我在 MacOS X 主机上的构建命令是

docker build -t my-image --ssh default .

我能够使用我的 ed25519 SSH 密钥从 MacOS X 主机上的终端成功克隆。

任何想法如何解决这一问题?我意识到还有其他可用的解决方案,但这个似乎是最干净的,因为它没有将我的私钥存储在图像中。

【问题讨论】:

    标签: docker dockerfile


    【解决方案1】:

    不要在镜像构建中克隆 repo,你根本不需要这样做。

    只需将 Dockerfile 放在 repo 的 / 中(也将其提交到 repo 以对其进行版本控制),然后使用镜像内的 Dockerfile 命令复制 repo 文件:COPY . . 第一个点是源,即您机器上的当前目录,即您的 git 存储库,第二个点是目标,即图像中的工作目录。您构建并发布映像,将其推送到 docker 注册表,以便其他人可以拉取并开始使用它。如果你想在服务器的帮助下构建和发布更复杂的东西,请查看 CI/CD 技术。

    【讨论】:

    • 我需要来自 git LFS 存储库的二进制文件,我们希望将其包含在图像中。
    猜你喜欢
    • 2011-10-08
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    • 2023-03-24
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    相关资源
    最近更新 更多