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

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

问题描述

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

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

FROM socialengine/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天全站免登陆