Howto detect and list OS in all LXD containers?

Is there a simple way to detect and list actual OS(operating systems) in all running and stopped LXD containers?

regards

You can try something like this, this will show what the os property of the image they were created from was. If they got created before we added logic to duplicate those keys, it will show as empty. It also won’t tell you anything about changes you may have done after the fact.

stgraber@castiana:~$ lxc list -cns,image.os:OS
+---------------------+---------+--------+
|        NAME         |  STATE  |   OS   |
+---------------------+---------+--------+
| c1                  | RUNNING | Alpine |
+---------------------+---------+--------+
| centos3             | STOPPED | centos |
+---------------------+---------+--------+
| centos4             | STOPPED | centos |
+---------------------+---------+--------+
| f32                 | STOPPED | Fedora |
+---------------------+---------+--------+
| keybase             | STOPPED |        |
+---------------------+---------+--------+
| snapcraft-lxd       | STOPPED | ubuntu |
+---------------------+---------+--------+
| snapcraft-lxdmosaic | STOPPED | ubuntu |
+---------------------+---------+--------+
| snapcraft-spotifyd  | STOPPED | ubuntu |
+---------------------+---------+--------+
| steam               | STOPPED | ubuntu |
+---------------------+---------+--------+
| ubuntu1804          | STOPPED |        |
+---------------------+---------+--------+
| ubuntu2004          | STOPPED |        |
+---------------------+---------+--------+
| v1                  | STOPPED |        |
+---------------------+---------+--------+
| win10               | STOPPED |        |
+---------------------+---------+--------+

nice thanks :slight_smile:
but my question was about actual OS containers - for example upgraded - with distro code/number
I wonder is there any solution beyond start every container and check /etc/issue

regards
PS.I am thinking… what about to inform container LXD config when it is upgraded?
set some variables?

In general we do not allow containers to push information to LXD as that would allow bad acting containers to perform a DoS attack on the host.

Your best bet is probably some kind of lxc file pull of /etc/os-release or something along those lines.

1 Like