Docker 使用'Environment'键时未在容器中设置环境变量

Docker 使用'Environment'键时未在容器中设置环境变量,docker,docker-compose,Docker,Docker Compose,接下来,我尝试使用-etc=3设置一个环境变量,并在compose文件中如下所示: services: balancer: environment: - TC=3 但在容器运行时未设置该变量 有人知道我做错了什么吗 我正在使用: docker compose 1.23.1,构建b02f1306 Docker 18.06.1-ce,构建e68fc7a 您设置环境的方式是正确的。使用此编写文件 version: '2' services: test: envi

接下来,我尝试使用
-etc=3
设置一个环境变量,并在compose文件中如下所示:

services:
  balancer:
    environment:
      - TC=3
但在容器运行时未设置该变量

有人知道我做错了什么吗

我正在使用:

  • docker compose 1.23.1,构建b02f1306
  • Docker 18.06.1-ce,构建e68fc7a

您设置环境的方式是正确的。使用此编写文件

version: '2'
services:
  test:
    environment:
      - HELLO=WORLD
    image: alpine
    command: env
我得到了这个输出

$ docker-compose -f test-compose.yml up
Creating network "sandbox_default" with the default driver
Creating sandbox_test_1 ... done
Attaching to sandbox_test_1
test_1  | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
test_1  | HOSTNAME=e2eb1a0da23e
test_1  | HELLO=WORLD
test_1  | HOME=/root
sandbox_test_1 exited with code 0
如果您希望能够重写在compose文件中编写的变量,则需要使用
${var_name}
语法,例如

environment:
  - HELLO=${hello_value}

您如何知道环境未设置?