7

i currently looking for running nmcli in a docker container

nmcli work great on my host but if i'm starting a privileged container nmcli does not work.

to start my container

sudo docker run --privileged --net host -it image_with_network-manager /bin/bash

and then running nmcli

nmcli dev wifi  => Error: Could not create NMClient object: Could not connect: No such file or directory

ifconfig inside my container is ok , i have eth0 and wlan0 of the host

Maxime Krier
  • 81
  • 1
  • 1
  • 5
  • Could you maybe check with `strace` what is that file that cannot be opened, and let us know? (`strace nmcli dev wifi`) – jjmontes Oct 04 '18 at 21:01
  • thx you for helping me , here is the strace : https://pastebin.com/3PYdV7SW , there is a lot of : ENOENT (No such file or directory) , but i dont know if it is relevant or not – Maxime Krier Oct 05 '18 at 10:41
  • ENOENT are common, as many file open operations are tried in a lot of different paths where the file is not found (ENOENT) without that being an error. I usually start reading these kind of strace dumps from the end. We can see there's a `futex` call before the error, but I'm afraid this strace doesn't mean much to me (maybe it does to others who know better how nmcli internals). Maybe nmcli is trying to talk to other service and fails :/. Also read: https://success.docker.com/article/should-you-use-networkmanager – jjmontes Oct 05 '18 at 16:38

3 Answers3

5

I run my container like this:

docker run -d -it --privileged=true --net host --volume /var/run/dbus:/var/run/dbus [other args here] on Ubuntu18.04 and it works.

Note: --volume /var/run/dbus:/var/run/dbus but not --volume /var/run/dbus, and the above volume sharing flag is used to share the outer system's bus. If you need the container to have its own bus, you will need to configure differently.

weefwefwqg3
  • 961
  • 10
  • 23
3

The thing about networkmanager is that it runs on dbus. I did the same thing (stracing and seeing what was needed)

Try mounting /var/run/dbus as a volume.

sudo docker run --privileged --net host -it --volume /var/run/dbus image_with_network-manager /bin/bash

2

try in docker, this create own dbus in docker

docker run -it --net=host image_name
        
dbus-uuidgen > /var/lib/dbus/machine-id
mkdir -p /var/run/dbus
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address