简体   繁体   English

Docker-Compose 通过 .env 传递命令参数

[英]Docker-Compose Passing command args by .env

I often need to start Odoo server with different arguments.我经常需要使用不同的参数启动 Odoo 服务器。

So in docker-compose.yml, which is versioned, I specified the following:因此,在版本化的 docker-compose.yml 中,我指定了以下内容:

version: '3'
services:
  web:
    image: odoo:12.0
    command: odoo ${ODOO_ARGS}

and created a .env file with:并创建了一个 .env 文件:

ODOO_ARGS="--update=all"

This works well with a single argument, but it doesn't handle multiple arguments.这适用于单个参数,但不能处理多个参数。 For example if I try the following:例如,如果我尝试以下操作:

ODOO_ARGS="--database=myDb --update=all --stop-after-init"

the command will be evaluated as: odoo --database="myDb --update=all --stop-after-init"该命令将被评估为:odoo --database="myDb --update=all --stop-after-init"

I pretty sure it is a syntax issue, so I'd like to know how to pass multiple arguments to the command option through .env file.我很确定这是一个语法问题,所以我想知道如何通过 .env 文件将多个参数传递给命令选项。

It actually evaluates to odoo "--database=myDb --update=all --stop-after-init" just because you put quotes in the env file.它实际上评估为odoo "--database=myDb --update=all --stop-after-init"只是因为您在 env 文件中添加了引号。 Here is an example with several arguments in one string:这是一个在一个字符串中包含多个参数的示例:

docker-compose.yml docker-compose.yml

version: "3.7"

services:
  test:
    image: debian:buster
    command: find ${ARGS}

.env .env

ARGS=/ -name bash

Running this you'll get:运行这个你会得到:

test_1  | /bin/bash
test_1  | /usr/share/lintian/overrides/bash
test_1  | /usr/share/menu/bash
test_1  | /usr/share/doc/bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM