Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker stack deploy error about top-level object mappings

Following along with the Docker getting started guide, https://docs.docker.com/get-started/part3/#your-first-docker-composeyml-file, I'm running into an issue. I've created the docker-compose.yml file and verified that the contents are correct:

version: "3"
services:
  web:
    image: joshuabelden/get-started:part2
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
    networks:
      - webnet
networks:
  webnet:

I also verified that I can run my image outside of a swarm. After running the command:

 docker stack deploy -c docker-compose.yml getstartedlab

I'm getting the following error:

Top-level object must be a mapping

I can't seem to find any information on the error message.

like image 226
Joshua Belden Avatar asked Oct 03 '17 17:10

Joshua Belden


4 Answers

What I did to solve this is I removed the double quotes and made them single quotes to change version: "3" -> version: '3' This removed the error for me, also do this for all double quotes.

like image 69
bytec0de Avatar answered Nov 01 '22 04:11

bytec0de


You have to add the "volumes" where your code should be copied:

version: "3"
services:
  web:
    image: iconkam/get-started:part2
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    volumes:
      - .:/app
    ports:
      - "80:80"
    networks:
      - webnet
networks:
  webnet:
like image 21
Kamal Avatar answered Nov 01 '22 02:11

Kamal


This happens when Docker is running in Kubernetes mode and not swarm.

I fixed it by changing it to Swarm through settings > Kubernetesenter image description here

like image 2
Carra Avatar answered Nov 01 '22 02:11

Carra


You probably didn't save after modifying the docker-compose.yml file. So if you run 'docker compose up' without having saved, you get the error about top-level object mappings.

like image 2
user8996819 Avatar answered Nov 01 '22 03:11

user8996819