I am working through understanding how docker-compose.yaml works. I am trying to define a volume inside the compose file and to mount it at a mount point locally. I try to run a basic .yaml to mount my volume:
version: '3.2'
services: mydb: image: postgres volumes: - db-data:var/lib/postgres/data ports: - "5432:5432" volumes: - db-data: - driver: localBut when I run docker-compose down , I get an error:
$ docker-compose down
The Compose file '.\docker-compose.yml' is invalid because:
services.mydb.volumes 'type' is a required property
services.mydb.volumes 'type' is a required propertyI am new to this and still am understanding all the nuances of working with Docker. I think that my problem is that it's an either an indention error or how I am calling the version number with the extension, but I can't seem to understand the error.
1 Answer
The compose file is whitespace sensitive (this is yaml formatting). There are two different volume sections in a compose file, one where the volume is defined at the top level of indentation, and another where the volume is used within a service. You've attempted to define both within the service, and the second set of volumes is defined incorrectly for defining how to use the volume (it needs a target directory there). The following is what you want to try:
version: '3.2'
services: mydb: image: postgres volumes: - db-data:var/lib/postgres/data ports: - "5432:5432"
volumes: db-data: 2