srl-labs / containerlab

container-based networking labs
https://containerlab.dev
BSD 3-Clause "New" or "Revised" License
1.54k stars 263 forks source link

Confusing error when 'cmd' command fails #2284

Open jbemmel opened 1 day ago

jbemmel commented 1 day ago

For a Linux container I added the following cmd line:

cmd: 'sh -c "ip route replace default via 10.2.77.1"'

During initial startup, the subnet was unavailable so the command failed:

jvanbemmel@host:~$ docker logs clab-h1
ip: RTNETLINK answers: Network unreachable

However, that's not the error I get from clab. Instead:

ERRO[0000] failed to Statfs "/proc/0/ns/net": no such file or directory
hellt commented 1 day ago

this error means that this (or another) container existed before we reached the link creation phase. Did it?

jbemmel commented 1 day ago

Yes, it exists briefly and then terminates

jbemmel commented 1 day ago

cmd: "false" may reproduce the issue

hellt commented 1 day ago

this is "expected", since containers should not exit normally You should use exec to run commands inside the containers, and cmd is to change the daemon command that container runs

jbemmel commented 1 day ago

I made a mistake, but the error message could be clearer. Containerlab shouldn't even try to access an exited container