docker-compose.yml file errors on running docker-compose up

Here is my docker-compose.yml file:

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:

  • Where to hold Application Files - Docker
  • Docker container sometimes hangs and cannot be stopped
  • How to access a running docker containers external ip from within the container?
  • Can't get clipboard forwarding working, while being in Docker under SSH
  • Dynamically serving django docker containers
  • is it considered bad practice to create ssh key in container?
  • 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'
    

  • AAPT2 failing to merge resources on Docker
  • CHEF provisioning: SystemStackError: stack level too deep
  • Change system date time in docker containers without impacting the host
  • how to reach another container from a dockerised nginx
  • Error deploying Play Framework on AWS Beanstalk Docker
  • docker deploy vs docker stack deploy
  • 2 Solutions collect form web for “docker-compose.yml file errors on running docker-compose up”

    just remove last character “:” into string version:'2':

    after it docker-compose.yml must be like

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

    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. Since you are therefore not defining the version of the docker compose file, the rest of the file (which is version 2 oriented) fails. This is best resolved by adding a space after 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.

    Change your docker_compose.yaml file to:

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