gpt4 book ai didi

git - 使用 Git (Bitbucket) 拒绝 Dockerfile 公钥权限

转载 作者:太空狗 更新时间:2023-10-29 13:27:07 27 4
gpt4 key购买 nike

虽然我搜索了多个 SO QnA,但在使用 Dockerfile 来补充包含私有(private)存储库依赖项的 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

我在这里错过了什么?预先感谢您的协助!

最佳答案

Could not open a connection to your authentication agent.

这似乎是预料之中的:在一层中的 Dockerfile 中启动的代理不会在由 Dockerfile 的下一行创建的下一层中运行:然后停止从每一行运行的每个容器并 promise 为图像。

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

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

OP Chris指出in the comments :

layers are executed serially, with the current layer not having any context to prior ones.
Based on that "oh snap" moment, I went on to consolidate all RUN commands into a single RUN command using "&& \".
Everything is working as expected.

关于git - 使用 Git (Bitbucket) 拒绝 Dockerfile 公钥权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46966149/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com