Dockerfile 覆盖 ENV 变量 [英] Dockerfile Overriding ENV variable

查看:58
本文介绍了Dockerfile 覆盖 ENV 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Dockerfile,我想使用默认值配置 API.

I have a Dockerfile and I'd like to make the API configurable with a default value.

来自社交引擎/nginx-spa

FROM socialengine/nginx-spa

ENV API_URL 本地主机:6007

ENV API_URL localhost:6007

因此,当我运行此图像时,我将能够使用以下内容覆盖 localhost:6007:

So when I run this image I'd to be able to override the localhost:6007 with something like below:

docker run -e API_URL=production.com:6007 ui

docker run -e API_URL=production.com:6007 ui

这不起作用,我找不到有关如何执行此操作的明确说明.

This doesn't work and I can't find a clear explanation of how to do this.

有什么建议吗?

推荐答案

您所描述的应该可以正常工作.给定:

What you have described should work just fine. Given:

$ cat Dockerfile
FROM socialengine/nginx-spa
ENV API_URL localhost:6007
$ docker build -t ui .
[...]

考虑一下:

$ docker run -it --rm ui env | grep API_URL
API_URL=localhost:6007

相比:

$ docker run -it --rm -e API_URL='production:6007' ui env | grep API_URL
API_URL=production:6007

docker run 命令行上传递 -e VARNAME=varvalue 将覆盖 Dockerfile 中的默认设置.

Passing a -e VARNAME=varvalue on the docker run command line will override a default set in your Dockerfile.

如果您看到不同的行为,请更新您的问题以准确显示您正在运行的命令和相关的输出.

If you are seeing different behavior, please update your question to show exactly the command you are running and the associated output.

更新

这里是完整的例子,记录下来供您观赏:

Here is the complete example, recorded for your viewing pleasure:

https://asciinema.org/a/a5a2n3exlyh4jkii4k0ivvqmd

这篇关于Dockerfile 覆盖 ENV 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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