我正在构建一个 docker 镜像,并且想从 bitbucket 克隆一个存储库。
如果我创建一个“debian”容器并逐步执行,一切都会正常进行。但是当我尝试创建映像时,它不起作用。
我已将密钥添加到 bitbucket 设置中。
这是我的Dockerfile
FROM debian:stretch
RUN apt-get update && apt-get -y upgrade && apt-get -y install nginx curl software-properties-common gnupg git
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN mkdir /backend
RUN npm install pm2 ts-node -g
WORKDIR /backend
RUN mkdir /root/.ssh
RUN echo -e "-----BEGIN RSA PRIVATE KEY-----\n(...)-----END RSA PRIVATE KEY-----" >> /root/.ssh/id_rsa
RUN chmod 400 /root/.ssh/id_rsa
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN git clone [email protected]:xxx/xxx.git
错误如下:
Cloning into 'xxx'...
Warning: Permanently added the RSA host key for IP address '104.192.143.3' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我怎样才能创建这个图像并使其正常工作?
答案1
如果您确定正确的公钥在 bitbucket 中,那么答案(根据我的经验)几乎总是 .ssh 文件夹及其中的文件的权限。我看到上面您只是创建了该文件夹和其中的私钥,但没有更新权限。
预期权限
.ssh 应该是:
drwx------ 2 user user 4096 Feb 6 11:18 .ssh
私钥:
-rw------- 1 user user 1675 Feb 6 11:18 id_rsa
最后,你的主目录至少应该不能被组或其他人写入,通常你需要:
drwx------ 84 user user 16384 Feb 16 18:23 user
综合起来:
chmod go-w /root
chmod 700 /root/.ssh
chmod 600 /root/.ssh/id_rsa