Docker Community Forums

Share and learn in the Docker community.

Top level and service-embedded volume specs in composer


(Devaxelafacom) #1

With say one volume used by one service, is there any difference at all between these two:

FIRST VERSION
volumes:
     localname : pathOnHost
services:
     web:
        <snip>
    volumes:
        - localname:pathOnContainer
SECOND VERSION
services:
     web:
        <snip>
    volumes:
        - pathOnHost:pathOnContainer

I’m really hoping there is no difference and that separating out volumes to describe at the top level with a kind of parameterised name used in services (even if only used in one service) is a mechanism that has effect only in the docker-compose parsing and not at container run-time or in any storage allocation or behaviour. I’ve read the documentation and it doesn’t quite answer this point. If my hope is correct then doing this “parametrised separation” provides a cool way to document what external storage is involved with a particular use of a compose and modify for say different web sites in development. If not, what are the differences please. I haven’t tested the first version so I hope I’m doing it right.

Thanks

andy