On Sat, Dec 19, 2015 at 12:13:07AM +0530, Harish Vishwanath wrote:
Hello
I wanted to understand if there is a way to get LXC container's ip address.
- virDomainInterfaceAddresses API only works for qemu/kvm and not with the
lxc driver.
What other options do I have?
If you're not looking for a libvirt-only solution, you can just use
`nsenter`:
nsenter -t <pid-inside-container> -n ifconfig
virsh -c lxc:/// lxc-enter-namespace <domain> --noseclabel
/sbin/ifconfig
libvirt: error : Expected at least one file descriptor
For what it's worth, I was able to do the above without a problem with
Fedora 23, running an alpine linux container (just unpacked the alpine
docker image):
sudo virsh -c lxc:/// lxc-enter-namespace alpine -- /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:16:3E:10:25:32
inet addr:192.168.124.4 Bcast:192.168.124.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:46 errors:0 dropped:0 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4034 (3.9 KiB) TX bytes:2022 (1.9 KiB)
I started the domain like this:
virt-install --connect lxc:/// --name alpine -r 512 \
--filesystem /containers/alpine/,/ \
-w network=default
When trying the same thing with a minimal Fedora domain, the above
failed because the Fedora filesystem I started with contained neither
`ip` or `ifconfig`...but worked fine once I installed the necessary
packages.
--
Lars Kellogg-Stedman <lars(a)redhat.com> | larsks @ {freenode,twitter,github}
Cloud Engineering / OpenStack |
http://blog.oddbit.com/