Need some help with my docker-compose: Services must be a mapping

Hello, I’m new to Docker and YML files. I’m currently trying to install Perforce on Docker with the help of this guide.

Everything seems to be fine, I mapped my own external directories but when running the following code I get several errors:

$ docker compose run -T --rm perforce \
tar czf - -C /etc/perforce/p4dctl.conf.d  . | \
tar xvzf - -C mnt/Perforce/p4dctl.conf.d/

services must be a mapping

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now

I tried to adjust the YAML with yaml-formatter but that also didn’t help.
I’m using Docker version 26.0.1, build d260a54

version: '3'
services: null
perforce: null
build: null
context: .
dockerfile: Dockerfile
restart: unless-stopped
volumes:
  - /mnt/Perforce/perforce-data:/perforce-data
  - /mnt/Perforce/dbs:/dbs
environment:
  - P4PORT=1666
  - P4ROOT=/perforce-data
ports:
  - 1666:1666

Could someone please help? Thanks!

Use 3 backticks before and after code/config to make it human readable. In yaml every space matters.

I’m not sure if you mean in the docker-compose or if you are talking about the post, I updated the post where I had the code in quotes before just in case.

Compare to a regular docker-compose.yml file, everything below service is usually spaced in, check examples in docs.

Ok I think I understand, it’s just confusing, I don’t know what’s to be parented under “services” or under “perforce”. I see examples with “volumes” being part of the “perforce” parent and others where “volumes” are just a section at the end without parents.

perforce is the name of the service.

version: '3'

services:
  perforce:
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
...

Thanks Bluepuma, using this I got it working, sadly my goal was to install Perforce on Docker while having the P4ROOT in a SMB share (so an external location) and that didn’t work due to permission issues, still thanks for the help!