[Lxc-users] Howto detect the containers host

Jäkel, Guido G.Jaekel at dnb.de
Thu May 26 07:34:35 UTC 2011


Hi all,

something related to the "Howto detect we're a LXC Container" is the question: "Howto detect from inside a container the name (or something equivalent) of the machine we're hosted on?" This might be of interest for administration level scripts on setups like the one 'm going to use: It's a farm of identical hosts where I may start the prepared containers on any of it, because all of this stuff is using a nfs-rootfs.


To be usable to run a isolated linx instance, at startup the uts information of the container is cloned from the host and the so-called nodename (which is availablie as 'hostname' or 'uname -n'  at user level) is replaced by the value of  lxc.utsname  from config.

Is there any possibility to let the container have access to the "original" nodename? Might it be made available on some  procfs  entry like /proc/lxc  - together with some other informations?

Another idea is to use, replace or append something to another uts field. Maybe the  domainname  field in the uts-struct copy for the container may be "abused" to hold the hosts nodename. To my knowledge if is only used by NIS/YP and is a separate to the dnsdomainname for DNS nameresolving. And will probably be overwritten by NIS/YP startup, if used.

Or maybe we may append something to the release field. It is filled with the kernel version string, like '2.6.37-gentoo'. Here we may append something to get "<version>-lxc@<host's nodename>"


To have another way in addition -- because on some init frameworks this passed environment isn't available --  we may add an analogous putenv() call to the lxc_start.c|main to pass "host=<hostname>" to the containers environment.


Grüße

Guido





More information about the lxc-users mailing list