I’m in the process of porting a Python application from a custom Yocto project built on a Colibri module to a Docker container to run on Torizon OS on an AM62 Verdin module. One of the items that I am struggling with is getting my networking set up properly. On the Colibri board we were able to access nmcli
using subprocess.run
to handle all of the networking. After reading over a lot of different articles and threads I haven’t been able to come up with what would be the best method here.
My use case provides users with a web interface through a flask server. From the web interface, the user needs to be able to adjust the ethernet IP of the board as well as scan for and connect to different wifi networks.
I’ve seen some threads that discuss using NMCLI or straight DBUS and others that suggest not doing this from the container, but creating a host application that would communicate to the containerized application to handle the changes.
Is there a best practice method here?
I’ve been trying to use the NMCLI route since that is what my code is already set up to work with, but I am struggling with this. I have NMCLI and network-manager in my container, but I cannot seem to get network-manager to start when the container is started, I have to manually start it.
This is my docker-compose service:
build:
context: .
dockerfile: Dockerfile.debug
image: ${LOCAL_REGISTRY}:5002/myapp-debug:${TAG}
network_mode: "host"
ports:
- 6502:6502
- 6512:6512
- 5000:5000
- 502:502
environment:
- APP_ROOT=/home/torizon/app
cap_add:
- NET_ADMIN
volumes:
- appdata:${APP_ROOT}/src/data
- /etc/NetworkManager:/etc/NetworkManager
When I start bash in my container I have run cmd NetworkManager
to get nmcli to work.
root@verdin-am62-15207040:/# nmcli
Error: NetworkManager is not running.
root@verdin-am62-15207040:/# NetworkManager
I have tried starting NetworkManager through my entrypoint.sh using this:
if ! pgrep -x "NetworkManager"; then
NetworkManager
fi
Then I get this error:
root@verdin-am62-15207040:/# nmcli
Error: Could not create NMClient object: Could not connect: Connection refused.
root@verdin-am62-15207040:/# NetworkManager
root@verdin-am62-15207040:/# nmcli
Error: Could not create NMClient object: Could not connect: Connection refused.
Any help here would be greatly appreciated. If there is a best practice for handling this, please let me know.