Docker compose error “In file './docker-compose.yml', service 'punjab' must be a mapping not a string.”

◇◆丶佛笑我妖孽 提交于 2019-12-10 13:39:37

问题


I am getting a strange error in my docker-compose.yml file.

I have prepared a docker-compose file for the stack punjab connection manager, ejabberd and mysql.

Below is the docker-compose.yml file

version: '2'
services:
  punjab:
    image:punjab
    ports
     - 5280:5280
    links
     - ejabbberd:ejabberd
  ejabberd:
    image: ejabberd
    depends-on:
      - mysql
    links:
      - mysql:mysql
  mysql:
    image:mysql

When I run the command docker-compose up from the command line and from the same directory where I have the docker-compose.yml file, I get the following error.

ERROR: In file './docker-compose.yml', service 'punjab' must be a mapping not a string.

I parsed the yml file using yamllint as well and the file is correctly formatted.


回答1:


Although in theory the file format may look correct, there are some things that are wrong.

They are:

  1. Use depends_on instead of depends-on because that is the correct syntax.

  2. For best practice, use a blank space before informing the image like: image: punjab.

  3. On ports and links at punjab service, you forget the colon :

  4. The images ejabberd and punjab do not exist on Docker Hub so they must exist in your local repository.

This is an example to use a docker-compose.yml:

version: '2'
services:
  punjab:
    image: punjab
    ports:
      - "5280:5280"
    links:
      - ejabberd

  ejabberd:
    image: ejabberd
    depends_on:
      - mysql
    links:
      - mysql

  mysql:
    image: mysql


来源:https://stackoverflow.com/questions/37632244/docker-compose-error-in-file-docker-compose-yml-service-punjab-must-be-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!