Short vs long volume declaration syntax behavior

Consider the following YAML code in my docker-compose.yml file that sets up volume mounting (using version 3.7), using short form syntax as specified in the docs:

    - ./logging:/var/log/cron

This maps the relative path logging on my host machine to the /var/log/cron folder inside the container. When I run docker-compose up , if the logging folder doesn’t exist on my host machine, Docker creates it. All good there.

Now, if I change the above to long-form syntax:

    - type: bind
      source: ./logging
      target: /var/log/cron

Now when I run docker-compose up , it DOES NOT create logging folder if it doesn’t exist on my host machine. I get

Cannot create container for service app: b'Mount denied:\nThe source path "C:/Users/riptusk331/logging"\ndoesn\'t exist and is not known to Docker'

Does anyone know why the short form syntax creates the host path if it doesn’t exist, but the long form does not and gives an error?

I’m posting here more-so because I’m just genuinely curious about what the difference is that causes this behavior.

Works as documented:

Thank you, Metin. I am curious what the reason is for that difference? I am surprised there is not a bind mount option that allows creation of the host directory.

The rule Keep functions short and simple implies “Keep loop bodies short.

thanks for sharing this amazing information!