带有传递参数的 Dockerfile 运行 命令
Dockerfile RUN command with passed argument
我正在尝试将参数传递给 docker 构建以使其在 Dockerfile 中执行为
RUN --mount=type=secret,id=$SECRET_NAME cp /run/secrets/$SECRET_NAME /etc/app/conf
但这会在构建期间失败,因为
> [8/8] RUN --mount=type=secret,id=mysecret cp /run/secrets/mysecret /etc/app/conf:
#13 0.224 cp: cannot stat '/run/secrets/mysecret': No such file or directory
但是当我直接在RUN
命令中使用它时
RUN --mount=type=secret,id=mysecret cp /run/secrets/mysecret /etc/app/conf
那行得通。
有什么想法吗?
您建议的功能(“秘密标识符本身的环境变量扩展”)似乎不受 BuildKit 支持,请参见。以下两个参考:
- https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md#run---mounttypesecret
- https://docs.docker.com/develop/develop-images/build_enhancements/#new-docker-build-secret-information
所以也许你可以重构你的 Dockerfile,这样它就不需要这个功能(顺便说一下,这会有阻碍 legibility/reproducibility 的缺点,因为人们不能仅仅通过查看就知道秘密标识符唯一的 RUN --mount=…
命令)。
我正在尝试将参数传递给 docker 构建以使其在 Dockerfile 中执行为
RUN --mount=type=secret,id=$SECRET_NAME cp /run/secrets/$SECRET_NAME /etc/app/conf
但这会在构建期间失败,因为
> [8/8] RUN --mount=type=secret,id=mysecret cp /run/secrets/mysecret /etc/app/conf:
#13 0.224 cp: cannot stat '/run/secrets/mysecret': No such file or directory
但是当我直接在RUN
命令中使用它时
RUN --mount=type=secret,id=mysecret cp /run/secrets/mysecret /etc/app/conf
那行得通。
有什么想法吗?
您建议的功能(“秘密标识符本身的环境变量扩展”)似乎不受 BuildKit 支持,请参见。以下两个参考:
- https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md#run---mounttypesecret
- https://docs.docker.com/develop/develop-images/build_enhancements/#new-docker-build-secret-information
所以也许你可以重构你的 Dockerfile,这样它就不需要这个功能(顺便说一下,这会有阻碍 legibility/reproducibility 的缺点,因为人们不能仅仅通过查看就知道秘密标识符唯一的 RUN --mount=…
命令)。