Binding a named-volume to a file in the container not working, only works for a directory

Viewed 64

In my docker-compose I have a named-volume like this config:/var/lib/myservice/config.yml. When I start the container I expect the config.yml file to be at: var/lib/docker/volume/myservice_config/_data on the host machine, but the _data folder is empty.

But if i write the named-volume without the filename like this: config:/var/lib/myservice then the config.yml appears in the _data folder

So does named-volume only work when pointing at a directory and not at a absolute path to a file?

1 Answers

A named volume is a directory, and you can't bind a directory to a file -- it doesn't make sense. That's the same thing as if you tried something like this:

docker run -v /path/to/a/directory:/var/lib/myservice/config.yml

Even if config.yml was a file in the underlying image, you've just mounted a directory on top of it.

Related