[lxc-users] Find out if one is inside a container

Bostjan Skufca bostjan at a2o.si
Wed Jul 15 02:08:00 UTC 2015


On 14 July 2015 at 22:33, Tycho Andersen <tycho.andersen at canonical.com>
wrote:

> On Mon, Jul 13, 2015 at 10:53:10AM +0200, Christoph Mathys wrote:
> > Is there an unhacky way of knowing if a script runs inside a
> > container? In my case, a sysV initscript that tries to load some
> > kernel modules needs to know if it runs inside the container, because
> > it must not load the modules in that case.
> >
> > The hacky way I came across so far was checking the control group of PID
> 1.
> >
> > Checking /proc/1/environ is considered OK? Or are there better ways?
>
> root at precise:/# cat /var/run/container_type
> lxc
>
> may be a better option for you.
>

/etc/init/container-detect.conf creates that file.

It seems that it gets that "lxc" string from environment variable
"container", but I can not find ATM how/where that is set and how it is
determined what to set. Maybe I am totally wrong and it may very well be
some upstart construct.

Does anyone know where that container variable gets its value from?

b.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20150715/5d2ba19f/attachment.html>


More information about the lxc-users mailing list