【发布时间】:2020-07-12 12:33:00
【问题描述】:
这是一个有效的 Dockerfile:
# syntax=docker/dockerfile:1.0.0-experimental
FROM debian:buster-slim as base
# setup APT operation for noninteractive use
# This avoids a bunch of warnings like
# "debconf: unable to initialize frontend: Dialog"
ENV DEBIAN_FRONTEND=noninteractive
# install requirements
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
git \
openssh-client
# add a user
# RUN adduser --disabled-password app-user
# WORKDIR /home/app-user
# USER app-user
RUN mkdir --mode=0700 ~/.ssh
RUN printf "Host <bitbucket host>\n StrictHostKeyChecking no\n CheckHostIP no\n" >> ~/.ssh/config
RUN chmod 600 ~/.ssh/config
RUN --mount=type=ssh ssh-keyscan -t rsa <bitbucket host> >> ~/.ssh/known_hosts
RUN chmod 600 ~/.ssh/known_hosts
RUN --mount=type=ssh git clone --no-checkout 'ssh://git@<bitbucket host>/my/project.git'
我唯一删除的是实际的 bitbucket 主机。现在,不起作用的是激活“添加用户”评论后的三个逗号。如果激活了这三个命令,则构建失败并显示:
#20 [13/13] RUN --mount=type=ssh git clone --no-checkout 'ssh://git@bitbucke...
#20 digest: sha256:2ca1...
#20 name: "[13/13] RUN --mount=type=ssh git clone --no-checkout 'ssh://git@<bitbucket host>/my/project.git'"
#20 started: 2020-03-31 20:12:44.957895838 +0000 UTC
#20 0.648 Cloning into 'project'...
#20 1.170 git@<bitbucket host>: Permission denied (publickey).
#20 1.171 fatal: Could not read from remote repository.
#20 1.171
#20 1.171 Please make sure you have the correct access rights
#20 1.171 and the repository exists.
#20 completed: 2020-03-31 20:12:46.235264455 +0000 UTC
#20 duration: 1.277368617s
#20 error: "executor failed running [/bin/sh -c git clone --no-checkout 'ssh://git@<bitbucket host>/my/project.git']: exit code: 128"
rpc error: code = Unknown desc = executor failed running [/bin/sh -c git clone --no-checkout 'ssh://git@<bitbucket host>/my/project.git']: exit code: 128
这是 Docker 中的错误吗?我是否错过了这不应该以某种方式工作的暗示?我是否需要在 root 帐户和新用户帐户之间设置额外的转发级别? git/ssh 首先如何建立与代理的通信?我检查了/tmp、/run、安装和环境,但找不到管道/套接字。
显而易见的解决方法是以 root 身份克隆,然后在其上运行 chown -R,但这似乎非常不雅。另外,我显然想了解发生了什么。
【问题讨论】:
-
添加子选项
--mount=type=ssh,uid=1000(匹配app-user的数字用户ID)是否有效?看起来像 theuiddefaults to 0 这会使非 root 用户无法访问转发的代理套接字。 -
我相信这就是答案,@DavidMaze。但是,我宁愿使用
mode子选项。不过,我必须从 18.09 升级,因为该版本不理解这两个变体中的任何一个。