【问题标题】:Cannot get docker to clone private git repos无法让 docker 克隆私有 git 存储库
【发布时间】:2019-06-04 11:20:43
【问题描述】:

我有一个驻留在 IBM 私有云容器注册表上的 docker 映像。从那里,它被远程获取和构建,以部署在 Kubernetes 集群上。安全性不是该注册表的问题,因此目前我们将 SSH 密钥作为变量传递。我目前的Dockerfile如下:

FROM ubuntu:14.04
ARG SECRET_KEY="***"
ARG PUB_KEY="***"
RUN apt-get update
RUN apt-get install -y software-properties-common git ssh-client
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get update
RUN apt-get install -y python3-setuptools
RUN easy_install3 pip

RUN mkdir -p /app
COPY . /app
WORKDIR /app

RUN mkdir /root/.ssh
RUN echo "${SECRET_KEY}" > /root/.ssh/id_rsa
RUN echo "${PUB_KEY}" > /root/.ssh/authorized_keys
RUN ssh-keyscan git.ng.bluemix.net >> /root/.ssh/known_hosts

RUN chmod 600 /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/authorized_keys
RUN chmod 644 /root/.ssh/known_hosts
RUN chmod 755 /root/.ssh

RUN echo "IdentityFile ~/.ssh/id_rsa" >> /etc/ssh/ssh_config

RUN bash ./build.sh
RUN pip install -r requirements.txt
CMD ["python3", "-u", "updater.py"]

build.sh 是一个 bash 脚本,它克隆了一些私有 git 存储库。使用此代码,我收到以下错误

Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

我查找了解决方案,他们涉及使用 ssh-agent。使用eval $(ssh-agent -s) 我得到Agent pid 8

但是,当我包含 ssh-add -l 或其他命令时,我会收到 Could not open a connection to your authentication agent.

编辑:基于不同的 SO 问题,我将 Dockerfile 中的几行更改为具有

RUN eval `ssh-agent s` && \
    ssh-add /root/.ssh/id_rsa && \
    bash ./build.sh

当我读到 ssh-agent 在调用 ssh-add 时被杀死。但是,当密钥是未加密的密钥时,我会收到Enter passphrase for /root/.ssh/id_rsa

【问题讨论】:

  • 您可以生成一个无密码短语的密钥供此 Docker 映像使用。
  • 这是一个免密码密钥。

标签: git docker ssh cloudant ibm-cloud-private


【解决方案1】:

我只是花了几个小时来解决这个问题,结果发现虽然需要我上面编辑的代码,但主要问题不在于 ssh-agent 或其他任何东西。我将我的私钥作为 dockerfile 中的默认变量传递,所以我退格了所有换行符。

事实证明,私钥中的新行很重要

添加一堆\n 以在私钥中创建换行符

【讨论】:

    猜你喜欢
    • 2021-02-04
    • 2014-10-30
    • 1970-01-01
    • 2015-11-15
    • 1970-01-01
    • 2021-09-01
    • 2018-11-23
    • 2019-01-26
    • 2023-04-01
    相关资源
    最近更新 更多