Search code examples
dockermacoselectronnmcli

Error: Could not create NMClient object: Could not connect: No such file or directory


I'm trying to run an electron app inside a docker container on my MacOS. I need "network manager" for the project because the electron app has a dependency on it. I am using Node 14 as base image.

I installed network manager using "apt install network-manager" and it installed: nmcli tool, version 1.14.6

But when I run nmcli command, I get the error: Error: Could not create NMClient object: Could not connect: No such file or directory.

I've tried looking around a lot, even asked AI tools for help, but I can't find a proper explanation or any solution.

I tried running the project on Ubuntu 16.04 base image and there after installing network-manager, the nmcli command worked fine (nmcli tool, version 1.2.6). So I decided to use that but only to realise that the electron app I am trying to setup, has a peer dependency to libgpiod package and that's not available for Ubuntu 16. I tried building it from source, didn't work.

I also tried to compile network-manager ver 1.2.6 in my node image, but that didn't work either.

Could someone help me understand how I can get nmcli command work in my node image? Or explain me why would it not work in node image but would work in ubuntu image?


Solution

  • The project as you've described it can't usefully run in a Docker container. Run it directly on the host system.

    NetworkManager is a tool to manage the host's network environment. Its primary interface appears to be via a D-Bus socket; this path is hard to access from in a container. (See for example DBus communication from docker to host and reverse.) Similarly, Electron is a toolkit to write desktop GUI applications using the Javascript Web ecosystem, but running GUI applications in Docker is tricky (Can you run GUI applications in a Linux Docker container?).

    In theory, if you (a) run as root on the host, so you can access the Docker socket; (b) bind-mount /var/run/dbus to get access to the host's DBus socket; and (c) do the extended work to get access to the host display; then it might be possible to run this

    xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f /tmp/docker.xauth nmerge -
    sudo docker run \
      -v /var/run/dbus:/var/run/dbus \
      -v /tmp/.X0-unix:/tmp/.X0-unix \
      -v /tmp/docker.xauth:/root/.Xauthority
      -e DISPLAY=:0.0 \
      your-image
    

    This will only work on a native Linux host system, and then only if you're using the Docker Engine directly and not Docker Desktop.

    Running outside a container will be far easier, particularly since this last command block is something your end user will need to run every time they run the application.