docker-compose.yml在运行docker上的文件错误 – 组成
这是我的docker-compose.yml文件:
version:'2': services: redis: image: redis environment: - HOST='localhost' - PORT=6379 ports: -"0.0.0.0:${PORT}:6379"
运行docker时出现这个错误 – 编写:
ERROR: The Compose file './docker-compose.yml' is invalid because: Invalid service name 'services' - only [a-zA-Z0-9\._\-] characters are allowed Unsupported config option for services: 'redis'
只要删除最后一个字符“:”到stringversion:'2':
之后它docker-compose.yml
一定是像
version:'2' services: redis: image: redis environment: - HOST='localhost' - PORT=6379 ports: -"0.0.0.0:${PORT}:6379"
你的文件有多个问题。 导致语法错误的是在第一行有一个额外的冒号:
version:'2':
这样你可以定义一个标量string键值version:'2'
,其值为null
。 由于您因此未定义泊坞窗撰写文件的version
,文件的其余部分(面向版本2)失败。 最好通过在version:
之后添加空格来解决这个问题version:
此外,您的ports
定义不正确,值应该是sequence
/ list
,并且您再次指定标量string-"0.0.0.0:${PORT}:6379"
因为在初始破折号之后没有空格。
将您的docker_compose.yaml
文件更改为:
version: '2' # ^ no colon here # ^ space here services: redis: image: redis environment: - HOST='localhost' - PORT=6379 ports: - "0.0.0.0:${PORT}:6379" # ^ extra space here