lima-vm / lima

Linux virtual machines, with a focus on running containers
https://lima-vm.io/
Apache License 2.0
15.23k stars 600 forks source link

Can't create a socket in a shared directory #1824

Open jemershaw opened 1 year ago

jemershaw commented 1 year ago

Description

I am not sure if this is a limitation on the macOS side or something with qemu but when I try to create a socket in the vm it fails to even create the socket. I will continue to look into this issue but I wasn't sure if anyone else ran into this issue before.

                    'c.          jemershaw@epona-work
                 ,xNMM.          --------------------
               .OMMMMo           OS: macOS 13.5.2 22G91 arm64
               OMMM0,            Host: Mac14,9
     .;loddo:' loolloddol;.      Kernel: 22.6.0
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 4 days, 17 hours, 28 mins
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 103 (brew)
 XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: zsh 5.9
;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: 3840x1620
:MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: yabai
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.    Terminal: tmux
 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   CPU: Apple M2 Pro
  .XMMMMMMMMMMMMMMMMMMMMMMMMK.   GPU: Apple M2 Pro
    kMMMMMMMMMMMMMMMMMMMMMMd     Memory: 3053MiB / 16384MiB
     ;KMMMMMMMWXXWMMMMMMMk.
       .cooc,.    .,coo:.

To reproduce the issue:

# Start the ubuntu-lts vm
┗╸❯❯❯ limactl start template://ubuntu-lts
# list the ubuntu-lts vm
┗╸❯❯❯ limactl list ubuntu-lts
NAME          STATUS     SSH                VMTYPE    ARCH       CPUS    MEMORY    DISK      DIR
ubuntu-lts    Running    127.0.0.1:55327    qemu      aarch64    4       4GiB      100GiB    ~/.lima/ubuntu-lts
# Login to the vm
┗╸❯❯❯ eval $(limactl show-ssh ubuntu-lts) -A
# Test that you can create a socket in the vm
jemershaw@lima-ubuntu-lts:~$ nc -lkUv aSocket.sock
Bound on aSocket.sock
Listening on aSocket.sock
^C
# navigate to a shared directory
jemershaw@lima-ubuntu-lts:~$ cd /Users/jemershaw
# Try to start a socket in the shared directory (fails)
jemershaw@lima-ubuntu-lts:/Users/jemershaw$ nc -lkU aSocket.sock
nc: Operation not supported
jandubois commented 1 year ago

This is not going to work; the socket needs to be forwarded from the VM to the host; you can't just create it in a mounted directory. Here is an example from the docker-rootful template, that does this: https://github.com/lima-vm/lima/blob/a26c6b20d63b714f3253c1685b977d3ffe7f492c/examples/docker-rootful.yaml#L75-L77

jemershaw commented 1 year ago

@jandubois even if the socket is generated from the vm and only used from the vm?

jemershaw commented 1 year ago

I know this works with docker desktop on mac because when I switched over to use lima this stopped functioning.

jandubois commented 1 year ago

@jemershaw I would think so, but maybe depends on the mount type. Why would you want to create the socket inside the shared directory if you don't want to connect to it from the host?

jandubois commented 1 year ago

Maybe try with 9p (or virtisfs if you are using vz emulation) and see if that works?

jemershaw commented 1 year ago

I pass in docker run -it -rm -v $HOME:$HOME ... and use ssh and other things that use sockets in the home directory. The first thing I tried was the different mount types 9p but that didn't work. I'll try virtiofs next. Thanks for the quick reply.