我能够在下面的 dockerfile 中的第四步安全地克隆,但无法在最后一步中克隆。
我有一个用例,我必须在 dockerfile 中创建用户。更改用户为 dockerfile 后,ssh 克隆失败
# syntax=docker/dockerfile:experimental
FROM python:3.10-bullseye
ARG APP_PATH=/opt/app
RUN mkdir -p /etc/ssh && ssh-keyscan bitbucket.org > /etc/ssh/ssh_known_hosts
RUN --mount=type=ssh git clone [email protected]:workspace/repo.git
# Create user and set ownership and permissions as required
RUN useradd -ms /bin/bash -u 999 john
RUN mkdir "$APP_PATH" && chown john:john -R "$APP_PATH"
WORKDIR $APP_PATH
USER john
COPY --chown=john:john . .
RUN --mount=type=ssh git clone [email protected]:workspace/repo.git
docker构建命令:
docker build --ssh default -t app2:latest -f Dockerfile .
您需要更改文件夹和文件权限,如下所示:
RUN mkdir -p /etc/ssh && chmod 0755 /etc/ssh && ssh-keyscan bitbucket.org > /etc/ssh/ssh_known_hosts && chmod 644 /etc/ssh/ssh_known_hosts