Often Docker containers will have an extremely bare-bones Linux environment. In these scenarios, the ip
and ifconfig
commands are often not available. However I’d still like to be able to check what the Docker container’s IP address got assigned as. What do?
Well, one thing you can try is running hostname
which should still be installed in even the most bare-bones configs, at least AFAIK. Then you can ping that hostname from another machine and see if it resolves. That can fail in a variety of ways though.
The other option here is to use the information available in /proc/net/fib_trie
that will be available everywhere, since the kernel manages that. All credit here goes to this Medium article since I had never even seen this data before, nor knew of its existence.
They even provide these nice commands to run to parse the data in this “file”:
#!/usr/bin/env bash
## Get the primary and secundary IPs
awk '/\|--/ && !/\.0$|\.255$/ {print $2}' /proc/net/fib_trie
## Get only the primary IPs
awk '/32 host/ { print i } {i=$2}' /proc/net/fib_trie
Of course if awk
is also not available, you can simply cat /proc/net/fib_trie
and use the old eyeball-scanners to parse this data. ;]