0

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: local

But 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 property

I 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.

0

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:
  • Thank you @BMitch. I tried with the recommended indention for defining the target directory, but I get the error In file '.\docker-compose.yml', volume must be a mapping, not an array.. I think this also is an indention error, correct? – user7298979 Jan 4 at 16:47
  • @user7298979 I copy and paste too much, thought you had a second volume defined. There's no need to specify the driver as local, and the field is a map rather than an array for the top level volume definition. – BMitch Jan 4 at 18:40

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.