我在docker-compose.yml文件中配置了以下环境变量:
version: '3'
services:
server:
ports:
- 13045:3000
environment:
- NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'在尝试运行docker-compose up时,我会得到以下错误:
services.server.environment contains {"NODE_CONFIG": "{\"DATABASE_URL\":\"http://db:5984\"}"}, which is an invalid type, it should be a string我需要将环境变量设置为JSON字符串(参见https://github.com/lorenwest/node-config/wiki/Environment-Variables#node_配置)
我在这里做错什么了吗?我能让这件事起作用吗?
发布于 2017-06-23 12:21:42
环境变量定义为码头编写文件引用状态数组元素的VARIABLE=value。对于您的情况,需要将docker-compose.yml文件更改为:
version: '3'
services:
server:
ports:
- 13045:3000
environment:
- NODE_CONFIG='{"DATABASE_URL":"http://db:5984"}'发布于 2019-08-17 14:46:20
您需要移除变量前面的破折号。使用这样的语法:
environment:
NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'发布于 2022-09-23 21:40:41
version: '3'
services:
server:
ports:
- 13045:3000
environment:
NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'在NODE_CONFIG出去之前先冲过去。由于一些奇怪的原因,这个破折号看起来不被环境所接受。
下面的示例来自官方postgres码头枢纽https://hub.docker.com/_/postgres
# Use postgres/example user/password credentials
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
**QQ edit:**
Basically, dashes are lists and no dashes are mappings, so that is why environment variable must not have dashes
References:
https://stackoverflow.com/questions/64275361/docker-compose-yml-dash-syntax-in-yaml
https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.htmlhttps://devops.stackexchange.com/questions/1390
复制相似问题