[lxc-users] unique container id

Serge Hallyn serge.hallyn at ubuntu.com
Thu Feb 5 17:05:29 UTC 2015


Quoting U.Mutlu (for-gmane at mutluit.com):
> Serge Hallyn wrote, On 02/05/2015 04:47 PM:
> >Quoting U.Mutlu (for-gmane at mutluit.com):
> >>U.Mutlu wrote, On 02/01/2015 05:16 PM:
> >>>Hi,
> >>>how can a program or a shell script get the unique ID of the container
> >>>it is running inside? For example the name of the container.
> >>
> >>Hi people,
> >>has nobody an idea for this?
> >
> >Sigh.  Try ls -li /proc/self/ns/pid
> 
> Hi Serge,
> I think this is only an ephemeral ID, isn't it?
> I rather need a persistent ID for identifying the container.
> It would even suffice to get the name of the container (from within
> the container). Is this possible?

You have to do it yourself.  If the hostname.domainname is not
sufficient, you could have a startup hook (maybe lxc.hook.mount)
write a container id of your choice into, say,
$LXC_ROOTFS_MOUNT/etc/lxc_id.

-serge


More information about the lxc-users mailing list