Debugging docker-compose errors
Tags: docker, evidently, python, cli
Published: 2024-06-11 12:58:07


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1xfcn7yymjr5ioc240xs.png)



## Introduction:
Ever faced challenges while trying to run multi-containers with Docker? 
I was trying to operationalize my model monitoring and evaluation using Evidently, and had to create a setup to run multi-containers using Docker Compose. I was not expecting a smooth run when I ran  

```
docker-compose --build
```
in my terminal. 

Errors covered are: 

- Top-level object must be a mapping
- Additional property volume is not allowed
- Volumes must be a mapping
- * error decoding ‘ports’ : Invalid containerPort:  5432


## Top-level object must be a mapping:

If you get this error, "the top-level object must be a mapping" , when you run docker-compose up–build, you need to check your top-level elements, such as name, services, volume, version, e.t.c.  Specification of containers are made under applicable top-level elements. 
In my case, my top-level elements were all intact. I got to the next bug when I closed the docker-compose.yaml file and executed the docker-compose –build command from the terminal.

Resources:
[Stackoverflow](https://stackoverflow.com/questions/46550348/docker-stack-deploy-error-about-top-level-object-mappings): gave me the idea of closing the file and running again
[Docker documentation](https://forums.docker.com/t/docker-compose-top-level-object-must-be-mapping/139697): helped to understand what top level elements are
The Docker forum on the bug: was not useful to me.


## Additional property “volumnes” is not allowed
`docker-compose.yml: services_grafana Additional property volumnes is not allowed`
You will get an error message, similar to the one above if you add an unacceptable term in your configuration. In my case, I got the error because I typed in “volumnes” instead of “volumes” under the grafana container set-up. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/se203ly67ss7oyxvm0nv.png)


I had to read the error carefully to see the mistake. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hn6e57qpmdcc99kdj9k.png)


Resolving this moved me to the next error.

Resources I consulted:
[Stackoverflow](https://stackoverflow.com/questions/74040152/docker-compose-volumes-additional-property-is-not-allowed-or-volumes-must-be): Reading the challenges of others helped me to understand what could be the cause of the error, although my challenge was not there.
[Docker forum](https://forums.docker.com/t/docker-compose-additional-property-is-not-allowed/131767): this was not so helpful


##Error: Volumes must be a mapping
`.\docker-compose.yml:volumes must be a mapping`

This error is due to the wrong indentation of the volume specification (as a top-level element) or a mapping (under a top-level element).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipr5rhcwhajk0bchjd6w.png)

Implementing the right indentations will solve the problem.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cldzmavbeva7mig3fuev.png)


Resource 
[Stackoverflow](https://stackoverflow.com/questions/39555650/error-in-file-docker-compose-yml-service-volumes-must-be-a-mapping-not-a): The information here was enough

## error decoding ‘ports’ : Invalid containerPort:  5432

`* error decoding ‘ports’ : Invalid containerPort:  5432`

The PostgreSQL database uses port 5432 by default. You must ensure you are using the right port. Inspect your port specifications and indentation, close your yaml file, and run docker-compose-build in your terminal.

`docker-compose-build`


Reading your codes and understanding the tool you’re working with will reduce the hours you are likely to spend trying to get things to work. Always read documentation to understand the features, and use public forums like stackoverflow.




The docker-compose.yml file

```
version: '3.7'

volumes: 
  grafana_data: {}

networks:
  front-tier:
  back-tier:

services:
  db:
    image:  postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: Bender
    ports:
      - "5432:5432"
    networks:
      - back-tier

  adminer:
    image:  adminer
    restart: always
    ports:
     - "8080:8080"
    networks:
      - back-tier
      - front-tier

  grafana:
    image: grafana/grafana
    user: "472"
    ports:
      - "3000:3000"
    volumes:
      - ./config/grafana_datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml:ro
    networks:
      - back-tier
      - front-tier
    restart: always




```



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0iiil8099c8vaaczbrr.PNG)