在 Docker 中使用构建时参数的安全方法 [英] safe way to use build-time argument in Docker

查看:16
本文介绍了在 Docker 中使用构建时参数的安全方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个构建时间参数,我想用它来构建我的 Docker 文件;由于该论点本质上是机密的(私人仓库的 github 密钥),我不希望它最终出现在 docker 映像中.此引用来自有关构建时参数的官方 docker 文档.

I have a build time Argument with which I would like to build my Docker file; Since that argument is confidential in nature (github key of a private repo) I don't want that to end up in a docker image. This quotes is from official docker documentation regarding the build-time arguments.

警告:不建议使用构建时变量进行传递诸如 github 密钥、用户凭据等秘密.构建时变量具有 docker 历史记录的图像的任何用户都可以看到值命令.

Warning: It is not recommended to use build-time variables for passing secrets like github keys, user credentials etc. Build-time variable values are visible to any user of the image with the docker history command.

有人知道实现相同目标的推荐方法是什么吗?

Anybody know what is the recommended way to achieve the same?

推荐答案

使用 docker 18.09+,将是:docker build --secret id=mysecret,src=/secret/file(使用 buildkit).

With docker 18.09+, that will be: docker build --secret id=mysecret,src=/secret/file (using buildkit).

参见 PR 1288,宣布 在这条推文中.
--secret 现在由 API 版本 1.39 保护.

See PR 1288, announced in this tweet.
--secret is now guarded by API version 1.39.

例子:

printf "hello secret" > ./mysecret.txt

export DOCKER_BUILDKIT=1

docker build --no-cache --progress=plain --secret id=mysecret,src=$(pwd)/mysecret.txt -f - . <<EOF
# syntax = tonistiigi/dockerfile:secrets20180808
FROM busybox
RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret
RUN --mount=type=secret,id=mysecret,dst=/foobar cat /foobar
EOF

这篇关于在 Docker 中使用构建时参数的安全方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆