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

查看:115
本文介绍了在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 history
命令,图像的任何用户都可以看到生成时变量
值。

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 在此鸣叫中

-秘密现在由 API版本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天全站免登陆