NetworkManager: Access to nmcli within Docker container

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.