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

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.

  • installing `lightdm` in Dockerfile raises interactive keyboard layout menu
  • Can't read user input inside the Docker using Maven plugin
  • Inserting a conditional RUN statement inside a dockerfile
  • docker login behind proxy on private registry gives TLS handshake timeout
  • Docker registry mirror not used
  • Docker container with status “Dead” after consul healthcheck runs
  • 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.

  • How do we set docker containers to restart on reboot and on-failure?
  • How to remove a Docker image from the Bluemix Hub?
  • Docker Check if DB is Running
  • Docker container for Postgres 9.1 not exposing port 5432 to host
  • Docker Expected Runs in Foreground but Runs in Background
  • How to persist changes made by maven dependency:go-offline in docker image
  • One Solution collect form web for “Docker compose error “In file './docker-compose.yml', service 'punjab' must be a mapping not a string.””

    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
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.