colima icon indicating copy to clipboard operation
colima copied to clipboard

Can't mount a single file inside any container

Open p89fmathias opened this issue 2 years ago • 7 comments

Description

When i try to mount a file inside the container, it creates a directory without any content. Mounting directories works perfectly.

Version

Colima Version: 0.5.6 Lima Version: 0.18.0 Qemu Version: 8.1.2

Operating System

  • [ ] macOS Intel <= 12 (Monterrey)
  • [x] macOS Intel >= 13 (Ventura)
  • [ ] macOS M1 <= 12 (Monterrey)
  • [ ] macOS M1 >= 13 (Ventura)
  • [ ] Linux

Output of colima status

INFO[0000] colima is running using QEMU
INFO[0000] arch: x86_64
INFO[0000] runtime: docker
INFO[0000] mountType: sshfs
INFO[0000] socket: unix:///Users/fmathias/.colima/default/docker.sock

Reproduction Steps

  1. Create a file called test with "test" as text echo "test" > /tmp/test
  2. Run an ubuntu image with file mounted: docker run -it --rm -v /tmp/test:/tmp/test ubuntu:latest bash
  3. Cat file inside container:
cat /tmp/test
cat: /tmp/test: Is a directory

Expected behaviour

Inside container, we should get:

# ls /tmp/test
/tmp/test
# cat /tmp/test
test

Additional context

Using 9p mounts

$ cat ~/.lima/_config/override.yaml 
mountType: 9p
$ 

p89fmathias avatar Nov 02 '23 02:11 p89fmathias

Colima doesn't support mounting individual files. That's a very unusual specialty of Docker Desktop.

rfay avatar Nov 02 '23 03:11 rfay

Thanks for you reply @rfay ! Do you have plans to include this functionality ?

p89fmathias avatar Nov 02 '23 12:11 p89fmathias

I'm a user of Colima, not its maintainer. @abiosoft is the maintainer. I'm not sure that the underlying docker/moby server supports files, not sure how Docker Desktop does it. I'd be interested to know if OrbStack or Rancher Desktop can do it.

rfay avatar Nov 02 '23 16:11 rfay

The sample you gave would behave wrongly because the directory /tmp on the host is not mounted in the VM.

What you are experiencing is Docker's behaviour for a missing mounted file/directory, which is to create a corresponding empty directory in the container.

Can you try with a file within $HOME?

@rfay actually, it works fine and I have further verified it.

Thanks.

abiosoft avatar Nov 02 '23 16:11 abiosoft

Wow @abiosoft I've been avoiding that for years. Has this changed over time? Or am I just flat wrong? I think something in DDEV explicitly makes a directory to mount in order to mount a file for this reason. Or maybe it was Linux... :)

rfay avatar Nov 02 '23 16:11 rfay

@rfay

From my experience, the main problem is that if the file is missing/deleted/inaccessible for whatever reason, you get a folder in the container instead.

Afterwards if you re-create the missing file, Docker does not fix the volume mount until a restart. It can easily lead to wasted hours figuring what's going on.

Personally, I would avoid it if I have the choice. But it is useful and the user must ensure the file exists on the host before starting the docker container.

In the example given in this issue, the file doesn't exist in /tmp on the VM because it is not mounted by default. Hence, the created folder in the container.

abiosoft avatar Nov 02 '23 16:11 abiosoft

Hey guys, thanks for all the replies. Im not sure if I could understand exactly, but, let me detail a bit more:

$ ls /tmp/test 
/tmp/test
$ cat /tmp/test
test
$ docker run -it --rm ubuntu:latest ls -la /tmp/
total 8
drwxrwxrwt 2 root root 4096 Oct  4 02:12 .
drwxr-xr-x 1 root root 4096 Nov  3 12:25 ..
$ docker run -it --rm -v /tmp/test:/tmp/test ubuntu:latest cat /tmp/test
cat: /tmp/test: Is a directory
$

So:

  1. i have created a test file with "test" content, this file actually exists on host
  2. i have /tmp folder in the image/container and host
  3. when i try to mount the file /tmp/test inside /tmp, it mounts an empty directory instead of a single file

If i mount my host's /tmp inside container /tmp then the mounts misses some files and the ones he mounts turns to be directories.

$ ls /tmp
HP_Deskjet F4400 series_BR01SG2NF305C5_HP-COMMAND_34790	ad_mailbox_78532_0_0_evt_subevt_2			com.apple.launchd.tWvpe8981i
ad_721_lsystem_evt_subevt_0				ad_mailbox_78532_0_0_evt_subevt_3			com.brave.Browser.Sparkle.pid
ad_connect_queue_78534_0_evt_subevt_0			ad_mailbox_78532_0_1_evt_subevt_0			com.citrix.ctxworkspaceupdater.err
ad_gevt_nxgwevt_78534_3123690_10			ad_mailbox_78532_0_2_evt_subevt_0			drivefs_ipc.501
ad_gevt_nxgwevt_78534_3123690_11			ad_mailbox_78532_0_2_evt_subevt_1			drivefs_ipc.501_shell
ad_gevt_nxgwevt_78534_3123690_2				ad_mailbox_78532_0_2_evt_subevt_2			ovpnconnect-local-ipc.sock
ad_gevt_nxgwevt_78534_3123690_9				ad_mailbox_78532_0_2_evt_subevt_3			powerlog
ad_mailbox_78532_0_0_evt_subevt_0			ad_mailbox_78532_0_3_evt_subevt_0			test
ad_mailbox_78532_0_0_evt_subevt_1			colima							wimtxwdm203r-1
$ docker run -it --rm -v /tmp/:/tmp/ ubuntu:latest ls /tmp
colima	test  wimtxwdm203r-1
$ docker run -it --rm -v /tmp/:/tmp/ ubuntu:latest cat /tmp/test
cat: /tmp/test: Is a directory
$ 

p89fmathias avatar Nov 03 '23 12:11 p89fmathias