Docker Community Forums

Share and learn in the Docker community.

How to run nmcli command inside the container?

Hi @m
I also want to remove all wifi connection programmatically in the container running on my raspberry pi4. I was able to delete the specific connection on host OS with the following commands.

nmcli connection down id “ssid” || true
nmcli connection delete id “ssid” || true

Network manager is installed on host OS, but it is not installed in the container.
What I really want to is delete all wifi connections in my django container.
Here are all settings for django service in docker-compose.yml file

To use nmcli command in the container, I installed Network-manager by the following command.

apt-get update && apt-get install -y network-manager && systemctl mask NetworkManager.service

And I run executed the following command in the container

nmcli connection down id “TP-LINK-REAL3D” || true
nmcli connection delete id “TP-LINK-REAL3D” || true

But I got the following error.

root@raspberrypi:/app# nmcli connection down id “TP-LINK-REAL3D” || true
Error: Could not create NMClient object: Unknown or unsupported transport ‘"unix’ for address ‘“unix:path=/host/run/dbus/system_bus_socket”’.

  1. Is there any way to run nmcli commands directly in the container without installing network-manger in the container? I think it’s possible by exposing D-bus on host to the container, but I’m not sure yet.
  2. Even after network manager is installed on the container i still can’t run nmcli command. How can I fix it?

Thanks in advance.


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.