错误:撰写文件docker-compose.yml无效

时间:2020-01-10 15:16:10

标签: docker docker-compose

version: '3.7'
services:
  docker-mongo:
   image:
     - mongo:4.2.1
   ports:
     - "27017:27017"
   networks:
     - mynetwork


networks:
  mynetwork:

执行docker-compose config时出现以下错误:

Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

因此,根据错误消息,我尝试使用版本2.23.3 两者都导致相同的错误消息

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.docker-mongo.image contains an invalid type, it should be a string
  • Ubuntu 18.04.2 LTS
  • Docker版本18.09.6,内部版本481bc77
  • docker-compose版本1.17.1,版本未知

1 个答案:

答案 0 :(得分:0)

错误消息是自解释的,您的docker-compose应该如下所示:

version: '3.7'
services:
  docker-mongo:
   image: mongo:4.2.1
   ports:
     - "27017:27017"
   networks:
     - mynetwork


networks:
  mynetwork: