如何在docker-compose中传递参数?
Docker 1.9允许将parameter passing给dockerfile。 请参阅链接: https : //docs.docker.com/engine/reference/builder/#arg
我怎样才能通过在docker-compose.yml相同的arugments?
如果可能,请提供一个例子。
这个function是在Compose 1.6中添加的。
参考: https : //docs.docker.com/compose/compose-file/#args
services: web: build: context: . args: FOO: foo
现在可以将docker-compose v2 +作为build对象的一部分来完成;
泊坞窗,compose.yml
version: '2' services: my_image_name: build: context: . #current dir as build context args: var1: 1 var2: c
查看docker撰写文档 。
在上面的例子中,“var1”和“var2”将被发送到构build环境。
注意:任何具有与argsvariables同名的envvariables(通过使用environment块指定)将覆盖该variables。
现在docker-compose支持variablesreplace。
Compose使用运行docker-compose的shell环境中的variables值。 例如,假设shell包含POSTGRES_VERSION=9.3并且在docker-compose.yml文件中提供了这个configuration:
db: image: "postgres:${POSTGRES_VERSION}"
当你用这个configuration运行docker-compose up ,Compose将在shell中查找POSTGRES_VERSION环境variables并replace其中的值。对于本例,Compose在运行configuration之前将imageparsing为postgres:9.3 。