Docker Community Forums

Share and learn in the Docker community.

Mount host file only if it exists

docker

(Shaoner) #1

Hi,

When mounting a host file as a volume, is there a way to prevent docker from creating a host directory if the file does not exist?
For example:

docker run -v ./hello.json:/hello.json:ro ...

actually creates a ./hello.json directory on the host

I mean, this is a weird behavior imo, it should raise an error/warning or nothing at all. It would probably break compatibility though.