简体   繁体   English

docker-compose.yml运行docker-compose时的文件错误

[英]docker-compose.yml file errors on running docker-compose up

Here is my docker-compose.yml file: 这是我的docker-compose.yml文件:

version:'2':  
services: 
    redis:
        image: redis  
        environment: 
            - HOST='localhost'
            - PORT=6379
        ports: 
            -"0.0.0.0:${PORT}:6379"

I get this error on running docker-compose up: 我在运行docker-compose时出现此错误:

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'

There are multiple problems with your file. 您的文件存在多个问题。 The one causing the syntax error is that you have an extra colon on the first line: 导致语法错误的是您在第一行有一个额外的冒号:

version:'2': 

that way you define a scalar string key version:'2' with value of null . 这样你就可以定义一个标量字符串键version:'2' ,其值为null Since you are therefore not defining the version of the docker compose file, the rest of the file (which is version 2 oriented) fails. 因为您没有定义docker compose文件的version ,所以文件的其余部分(面向版本2)将失败。 This is best resolved by adding a space after version: 通过在version:之后添加空格可以最好地解决此问题version:

In addition your ports definition is incorrect, the value for that should be a sequence / list , and you again specify a scalar string -"0.0.0.0:${PORT}:6379" because there is no space after the initial dash. 此外,您的ports定义不正确,其值应为sequence / list ,并再次指定标量字符串-"0.0.0.0:${PORT}:6379"因为初始短划线后没有空格。

Change your docker_compose.yaml file to: 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

just remove last character ":" into string version:'2': 只需将最后一个字符“:”删除为字符串version:'2':

after it docker-compose.yml must be like 之后它docker-compose.yml必须像

version:'2'
services: 
redis:
    image: redis  
    environment: 
        - HOST='localhost'
        - PORT=6379
    ports: 
        -"0.0.0.0:${PORT}:6379"

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

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