variables - 如何在 Dockerfile 中定义变量?

标签 variables docker dockerfile

在我的 Dockerfile 中,我想定义以后可以在 Dockerfile 中使用的变量。

我知道 ENV 指令,但我不希望这些变量成为环境变量。

有没有办法在 Dockerfile 范围内声明变量?

最佳答案

您可以使用 ARG - 见 https://docs.docker.com/engine/reference/builder/#arg

The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg <varname>=<value> flag. If a user specifies a build argument that was not defined in the Dockerfile, the build outputs an error.

Can be useful with COPY during build time (e.g. copying tag specific content like specific folders) For example:

ARG MODEL_TO_COPY
COPY application ./application
COPY $MODEL_TO_COPY ./application/$MODEL_TO_COPY

While building the container:

docker build --build-arg MODEL_TO_COPY=model_name -t <container>:<model_name specific tag> .

关于variables - 如何在 Dockerfile 中定义变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33935807/

相关文章:

docker - 如何使用 consul 和 gliderlabs/registrator 防止僵尸服务?

python - 本地 pypi 服务器在注册包时告诉我 403 Forbidden

postgresql - 将在Docker容器中运行的PostgreSQL服务器连接到Wild-fly Docker容器?

postgresql - 使用 Dockerfile 运行带有 PostgreSql 的 Tomcat

variables - Prolog 中的变量绑定(bind)

javascript - 变量无故改变

docker - Docker镜像-apt get update -y错误

docker - 通过docker访问的Swagger UI不起作用

c# - 在 C# 中允许用户定义的字符串

java 实例方法和变量的继承解析