【问题标题】:Dockerfile Public Key Permission Denied using Git (Bitbucket)使用 Git (Bitbucket) 拒绝 Dockerfile 公钥权限
【发布时间】:2018-04-08 12:49:28
【问题描述】:

尽管我已经搜索了多个 SO QnA,但在使用 Dockerfile 为包含私有 repo 依赖项的 Node.js 应用程序提供水合时,我无法完全解决我的问题。这是我的 Dockerfile 的相关部分:

FROM node:8.7.0-alpine

RUN \
    # install required packages
    apk --no-cache add --virtual \
    builds-deps \
    build-base \
    python \
    git \
    openssh-client

# git config
RUN git config --global user.name "*****"
RUN git config --global user.email "*****@*****.co"

# *******************
# install git ssh key
# *******************
# create ssh dir
RUN mkdir /root/.ssh

# Copy over private key from volume and set permissions
ADD bitbucket_rsa /root/.ssh/bitbucket_rsa
RUN chmod 600 /root/.ssh/bitbucket_rsa
# start agent
RUN eval $(ssh-agent)
# load key into agent
RUN echo ssh-add /root/.ssh/bitbucket_rsa
RUN echo -e "Host bitbucket.org\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config

...

这是从 NPM 抛出的内容:

npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@bitbucket.org/someteamname/somereponame.git
npm ERR!
npm ERR! Warning: Permanently added 'bitbucket.org,XXX.XXX.XXX.XXX' (RSA) to the list of known hosts.
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-10-27T01_12_06_116Z-debug.log

我在这里缺少什么?提前感谢您的帮助!

【问题讨论】:

    标签: git ssh npm bitbucket dockerfile


    【解决方案1】:

    无法打开与您的身份验证代理的连接。

    这似乎是意料之中的:在您的 Dockerfile 中启动的一层代理将不会在 Dockerfile 的下一行创建的下一层中运行:然后停止从每一行运行的每个容器,然后作为图像提交。

    即使您将两个命令放在同一行,代理仍会在所述唯一行之后运行。

    代理开始 + ssh-add 命令应该是您的 CMD 脚本的一部分,该脚本也将作为前台进程运行。
    这意味着 Dockerfile 应该以 CMD script 结尾,'script' 是(复制的)脚本的路径,其中包含您要在容器中运行的内容,并且将从 ssh 代理和 ssh-添加命令。

    OP Chris 指出in the comments

    层是连续执行的,当前层与之前的层没有任何上下文。
    基于那个“哦,快”的时刻,我继续使用“&& \”将所有RUN 命令合并为一个RUN 命令。
    一切都按预期工作。

    【讨论】:

    • 虽然您的评论没有解决我的问题,但它确实指出了层是连续执行的,当前层与之前的层没有任何上下文。基于那个“哦,快”的时刻,我继续使用“&& \”将所有 RUN 命令合并为一个 RUN 命令。一切都按预期工作。
    • @Chris 太棒了!我已将您的评论包含在答案中以提高知名度。
    猜你喜欢
    • 2020-12-30
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 2017-10-30
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多