加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

多次运行Docker映像时传递不同的参数

发布时间:2020-12-16 03:24:59 所属栏目:安全 来源:网络整理
导读:我需要在运行Docker Image时给出一个参数,该参数将是0-3之间的一个数字. Dockerfile具有以下内容: WORKDIR "mydir/build"CMD ./maker oneapp /artifacts/oneapp_$1.log ; ./maker twoapp /artifacts/twoapp_$1.log ; ./maker -j13 threeapp /artifacts/thre

我需要在运行Docker Image时给出一个参数,该参数将是0-3之间的一个数字.

Dockerfile具有以下内容:

WORKDIR "mydir/build"
CMD ./maker oneapp > /artifacts/oneapp_$1.log ; ./maker twoapp > /artifacts/twoapp_$1.log ; ./maker -j13 threeapp > /artifacts/threeapp_$1.log

我将多次运行同一个Docker Image,因此需要将日志保存在/ artifacts中,并在适当时附加_0,_1,_2,_3.

我尝试将其保存在Docker文件中,但不想在运行docker时将整行作为参数传递.

ENTRYPOINT [“/bin/bash”]

./maker oneapp > /artifacts/oneapp_$1.log ; ./maker twoapp >
/artifacts/twoapp_$1.log ; ./maker -j13 threeapp >
/artifacts/threeapp_$1.log

是否有可能做到这一点?我需要在Dockerfile中修改什么才能做我想要的?

最佳答案
只需将您的参数作为ENV注入即可.

声明一个ENV in your Dockerfile.

ENV suffix 0
./maker oneapp > /artifacts/oneapp_${suffix}.log

The environment variables set using ENV will persist when a container is run from the resulting image.
You can view the values using docker inspect,and change them using docker run --env <key>=<value>.

这样,您可以声明ENV on docker run,并从运行容器中的值中受益.

the operator can set any environment variable in the container by using one or more -e flags,even overriding those mentioned above,or already defined by the developer with a Dockerfile ENV:

以您的情况为例:

docker run -e suffix=2 <image_name>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读