Finding the image name that a container uses

Is there a way to discover the name (aka description) of the image that a container was created with? I know that with more recent versions of lxd, I can do lxc list -c nf to get the container name and the base image id, but is there a way to link that id, i.e., 84a71299044b back to Ubuntu 18.04.1 LTS?

I’m asking, since if I have a fleet of LXD containers, I would like a quick an easy way to say “list all containers and the images they were built from” so I can quickly grok which OS is deployed…

I have the following options in a container configuration (listed with lxc config show <container>).

...
config:
  image.architecture: amd64
  image.description: ubuntu 18.04 LTS amd64 (release) (20180617)
  image.label: release
  image.os: ubuntu
  image.release: bionic
  image.serial: "20180617"
  image.version: "18.04"
...

Show with for example: lxc list -c 'n,image.description'.

The released container images can be found at
https://cloud-images.ubuntu.com/releases/bionic/

It looks like this:

...
[DIR] release-20180613/       14-Jun-2018 07:02    -   Released Image
[DIR] release-20180617/       18-Jun-2018 07:01    -   Released Image
[DIR] release-20180724/       25-Jul-2018 07:01    -   Released Image
...

If you use the serial number, you are directed to the correct directory of the released container image.
From there, you can look into SHA1SUMS and identify your exact container image.

I downloaded all checksum files for 18.04 and searched for 84a71299044b. I did not get a match. Did you use ubuntu:18.04 or images:18.04?

It should also be possible somehow to extract the base container image from LXD.

Hi,

@mikma give me the clue I was looking for. Using a combination of jq and mlr (miller), I was able to do this:

%   lxc list --format json | jq -r '.[] | .name + "," + .config["image.description"]' | mlr --csv --opprint label container,distro                                                                          
container distro
foo       ubuntu 18.04 LTS amd64 (release) (20180911)
bar       ubuntu 18.04 LTS amd64 (release) (20180808)
baz       ubuntu 17.10 amd64 (release) (20180222)
foo2      ubuntu 16.04 LTS amd64 (release) (20180405)
bar2      ubuntu 18.04 LTS amd64 (release) (20180911)
baz2      ubuntu 16.04 LTS amd64 (release) (20180405)

Nice!

better for me:

lxc list --format json | jq -r '.[] | .name + ", " + .config["image.description"]' | mlr --implicit-csv-header --csv --opprint label container,distro

First, a container can have no image (if imported from physical) hence the space after “,”
Also, without implicit-csv-header first container is missing for me (Ubuntu 18.04, jq and miller from apt)

and well, with a recent lxd version (>= 3)

lxc list -c n,image.description:image

don’t need to install additional software after all.

1 Like

Even better!

Thank you @gpatel-fr!