【docker】 yaml.scanner.ScannerError: mapping values are not allowed here in “./docker-compo…

An error was reported when starting docker compose

Command:

docker-compose up -d && docker-compose logs -f

Error code:

Solution

The reason for this error is that the YML format is incorrect. The YML format defined by Google is too strict. Every colon must be followed by a space

Original format:

version:"3"
services:
  web:   
    image: licerlee/friendlyhello:v1
    deploy:
      replicas:5
      resources:
        limits:
          cpus:"0.1"
          memory:50M
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
    networks:
      - webnet
networks:
  webnet:

Change to:

version: "3"
services:
  web:
   
    image: licerlee/friendlyhello:v1
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
    networks:
      - webnet
networks:
  webnet:

Note: the above example is for illustration only, not the configuration file of my project

When executing the command:

It’s over!

Similar Posts: