NetworkManager: Access to nmcli within Docker container

Hi,

I use Torizon OS 6.8 with Docker (Project-Template Torizon → C#/Avalonia FB/DRM).
To get access to the NetworkManager, I change the Docker compose file to this (What is the best method for managing networks with TorizonOS and Docker containers? - #5 by dleberfinger)

volumes:
   - /etc/NetworkManager:/etc/NetworkManager
   - /var/run/dbus:/var/run/dbus
cap_add:
   - CAP_NET_ADMIN

When I try to run ‘nmcli’ in the Docker shell, the command is not found.

What is best practice to get ‘nmcli’ running within the Docker container?
Do I need to apt-get the NetworkManager in the project-file “Dockerfile.debug”?

For Docker “cap_add”, is it CAP_NET_ADMIN oder NET_ADMIN (like in the link above)?

Greetings
Lars

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Lars,

To run the ‘nmcli’ command within a Docker container on Torizon OS, you’ll need to ensure that the NetworkManager package is installed inside the container. Here’s how you can achieve this:

  1. Modify the Dockerfile: Add a line to install NetworkManager in your Dockerfile. If you’re using a Debian-based image, you can include the following:

    RUN apt-get update && apt-get install -y network-manager
    

    This will make ‘nmcli’ available inside the container.

  2. Update Docker Compose File: Ensure your Docker Compose file correctly mounts the necessary volumes and adds the required capabilities:

    volumes:
      - /etc/NetworkManager:/etc/NetworkManager
      - /var/run/dbus:/var/run/dbus
    cap_add:
      - NET_ADMIN
    

    Note that the capability should be specified as ‘NET_ADMIN’, which is the correct syntax.

  3. Rebuild and Restart the Container: After modifying the Dockerfile, rebuild your Docker image and restart the container to apply the changes.

By following these steps, you should be able to run ‘nmcli’ within your Docker container. This setup allows the container to interact with the host’s NetworkManager service, provided the necessary permissions and volumes are correctly configured.

I hope this helps! If you have any more questions, feel free to ask.

Best regards,
Toradex AI Assistant.

Please, also check if these links can help you solve your problem:

Networking with Torizon OS | Toradex Developer Center.

Greetings @Lars.ceta,

Was the response from the @ToradexAI sufficient to answer your questions?

Best Regards,
Jeremias

Hi Jeremias,

yes, I already marked as solution.

Bye,
Lars