compose icon indicating copy to clipboard operation
compose copied to clipboard

[BUG] Parsing error: Top-level object must be a mapping

Open akerouanton opened this issue 2 years ago • 3 comments

Description

I wrote a Compose file yesterday, and hit that strange error the first time I tried to docker compose up -d:

$ docker compose up -d
parsing <path>/docker-compose.yml: Top-level object must be a mapping

Since then, whenever I retry I get the right error message:

$ docker compose up -d
validating <path>/docker-compose.yml: services.foobar Additional property cmd is not allowed

I tried to create a new Compose file by retyping the exact same thing but I can't reproduce this issue.

This has already been reported in #10769.

Steps To Reproduce

Here's my Compose file:

services:
  foobar:
    image: busybox:latest
    cmd: ["sleep", "infinity"]
    networks:
      testnet:
        ipv4_address: 192.168.200.23
      front-tier:
        ipv4_address: 172.23.0.10

networks:
  testnet:
    name: testnet
    external: true
  front-tier:
    ipam:
      config:
        - subnet: 172.23.0.0/24

Compose Version

$ docker compose version
Docker Compose version v2.20.2-desktop.1

Docker Environment

docker info
$ docker info
Client:
 Version:    24.0.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2-desktop.1
    Path:     /home/akerouanton/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.20.2-desktop.1
    Path:     /usr/lib/docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /usr/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     /usr/lib/docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.6
    Path:     /usr/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/lib/docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /usr/lib/docker/cli-plugins/docker-scan
  scout: Command line tool for Docker Scout (Docker Inc.)
    Version:  0.20.0
    Path:     /usr/lib/docker/cli-plugins/docker-scout

Server:
 Containers: 2
  Running: 2
  Paused: 0
  Stopped: 0
 Images: 8
 Server Version: dev
 Storage Driver: vfs
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: crun io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1677a17964311325ed1c31e2c0a3589ce6d5c30d
 runc version: v1.1.8-0-g82f18fe
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.4.3-arch1-2
 Operating System: Debian GNU/Linux 11 (bullseye) (containerized)
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 31.05GiB
 Name: 21edbd5e13d9
 ID: 2af748a0-6e60-4b57-aa88-f1c61e3b5c55
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 40
  Goroutines: 56
  System Time: 2023-08-10T08:32:48.723676293Z
  EventsListeners: 0
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
         Access to the remote API is equivalent to root access on the host. Refer
         to the 'Docker daemon attack surface' section in the documentation for
         more information: https://docs.docker.com/go/attack-surface/

Anything else?

No response

akerouanton avatar Aug 10 '23 08:08 akerouanton

For this error:

Additional property cmd is not allowed

The field is named command, change to command: ['sleep', 'infinity'] and it should work.


For this error:

Top-level object must be a mapping

Hmm...if this happens again, could you send the raw Compose file? I'll see if we can make this error more descriptive as well.

milas avatar Aug 10 '23 13:08 milas

Hmm...if this happens again, could you send the raw Compose file? I'll see if we can make this error more descriptive as well.

Actually what I provided is the raw Compose file that triggered the issue. Unless you mean something like an xxd output to check BOM or other stuff that wouldn't appear in a text editor?

akerouanton avatar Aug 10 '23 15:08 akerouanton

Unless you mean something like an xxd output to check BOM or other stuff that wouldn't appear in a text editor?

Yeah, that's what I was wondering, but I looked at it a bit more and that error is not coming from the YAML library but the compose-go loader directly when we're doing some type assertions, so it somehow got unmarshaled as a type it didn't expect 🤔

milas avatar Aug 10 '23 18:08 milas