将参数传递给docker compose [英] Pass argument to docker compose
问题描述
在我的docker compose文件中,有一个我想在运行期间生成的动态字段。实际上,它是一个字符串模板:
In my docker compose file there is a dynamic field which I'd like to generate during the running. Actually it is a string template:
environment:
- SERVER_URL:https://0.0.0.0:${PORT}
我想配置此 PORT
参数动态
docker-compose run <service> PORT=443
在文档,我想可以使用 ARGS
参数集。但是没有任何信息可以在组合文件中使用
In documentation there is ARGS
parameters set I suppose I can use. But there is no information how can I use those inside compose file
推荐答案
在docker-compose中,参数仅在 dockerfile
。您可以像下面这样指定在上一级中正在做的事情:
In docker-compose, arguments are available and usefull only in dockerfile
. You can specify what you are doing in the level ahead like following:
#dockerfile
ARG PORT
ENV SERVER_URL "https://0.0.0.0:$PORT"
您可以在您的端口中设置端口docker-compose.yml:
Your port can be set in your docker-compose.yml:
build:
context: .
args:
- PORT=443
实际上是任何情况。您可以通过适合自己的运行命令来传递它:
It is actually an environment variable in any case. You can pass it through your run command if that fits to you:
PORT=443 docker-compose run <service>
#or
docker-compose run <service> -e PORT=443
这篇关于将参数传递给docker compose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!