docker / for-linux

Docker Engine for Linux
https://docs.docker.com/engine/installation/
749 stars 85 forks source link

Single file volume mounts not behaving the same as on macOS #1496

Open jamesmcguirepro opened 2 months ago

jamesmcguirepro commented 2 months ago

I have a docker-compose.yml that has a single file mounted as a volume that works fine on MacOS hosts.

ie:

---
version: '3'
...
    volumes:
    - "./volumes/init_script.sh:/some_folder/init_script.sh"
...

However, when I try this on a linux machine, the file is incorrectly mounted as a directory, which breaks my image.

thaJeztah commented 1 month ago

Bind-mounts happen on the daemon side, and default to assuming the path given is a directory. If your daemon is running remotely and doesn't have a file at the given location, and you're using the shorthand form for bind-mounts (<source>:<destination>), the daemon will automatically create the location on the host (which will be a directory), and bind-mount that in the container.

While on macOS, the daemon is also running "remotely" (in a VM) Docker Desktop makes sure that the files you're bind-mounting are present inside the VM before running the container.

jamesmcguirepro commented 1 month ago

Yeah, I think that tracks, except the file exists at the given location. Perhaps linux is having trouble finding the file or with the relative path (./) when dealing with a single file mount?

Moving the file to the some_scripts directory and mounting the directory like this seems to work fine on linux:


---
version: '3'
...
    volumes:
    - "./volumes/some_scripts/:/some_folder/"
...