使用环境变量创建Dockerfile

时间:2015-09-14 13:15:02

标签: docker environment-variables dockerfile

我正在尝试创建一个为用户运行命令的docker镜像。该命令将需要许多变量条目,特定于运行它的人。我尝试使用变量创建它,并且由于命令无法在构建时运行,因此该过程无法完成。然后我尝试使用' $ {varname:-possible value},然后我又进一步了。

我猜测部分问题可能是某些变量是URL,因为文件夹名称也是变量,正在接受。我确实尝试向网址中的所有特殊字符添加转义字符(' \'),所做的一切都让我得到了一个糟糕的替代品#39;而错误。

然后,我应该更改语法?

RUN /usr/bin/java -jar export.jar calendar \
    --output /var/www \
    --format public \
    --restUri ${one_uri:-http://my.site:8080/subdir/restservice} \
    --daysForward ${days_forward:-30}

1 个答案:

答案 0 :(得分:1)

I don't exactly get if your users is building their own Dockerfile or they are using your docker image directly, but if they create their own, then you can use ONBUILD to run a command that will when the user docker build their container.

https://docs.docker.com/reference/builder/#onbuild

else

you can just specify your own defaults like this

ENV days_forward "30"

and then they can easily overwrite that environment variable when they run your container.

相关问题