简体   繁体   中英

ERROR: The Compose file docker-compose.yml is invalid

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


networks:
  mynetwork:

When I execute docker-compose config I got the following error:

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/

So according to the error message I tried with version 2.2 and 3.3 both results in the same error message

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 version 18.09.6, build 481bc77
  • docker-compose version 1.17.1, build unknown

the error message is self explain, your docker-compose should be like below:

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


networks:
  mynetwork:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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