Aside from using lxc config edit <containername>, how do I set the 'description' for a container?

Hi,

Thanks in advance for reading this and for any guidance you can offer.

My apologies if this is already well covered somewhere, but I looked over the docs and didn’t see what variation of lxc config set or lxc config get was needed in order to retrieve or populate the description field for a container.

$ lxc version
Client version: 3.0.3
Server version: 3.0.3
$ lxc init ubuntu:18.04 forum-question-demo
Creating forum-question-demo
$ lxc config show forum-question-demo
architecture: x86_64
config:
  image.architecture: amd64
  image.description: ubuntu 18.04 LTS amd64 (release) (20190402)
  image.label: release
  image.os: ubuntu
  image.release: bionic
  image.serial: "20190402"
  image.version: "18.04"
  volatile.apply_template: create
  volatile.base_image: 663f6663aed66a22dd708c4b07514748221522b810008c55002fcc1dd81af377
  volatile.eth0.hwaddr: 00:16:3e:09:86:4b
  volatile.idmap.base: "0"
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":300000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":300000,"Nsid":0,"Maprange":65536}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":300000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":300000,"Nsid":0,"Maprange":65536}]'
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: ""

I want to get/set the description field as shown here:

...
profiles:
- default
stateful: false
description: ""

Is this supported?

Thanks.

The lxc config set ... command is for the keys under the config: section.
To edit the description, you would need to

 lxc config edit mycontainer

and then use your editor to edit in-place the description: field.

Alternatively, you can lxc config show mycontainer to get the full YAML configuration.
Then, edit the full YAML configuration by adding the description.
Finally, you can lxc config edit mycontainer < mynewconfiguration.yaml.

2 Likes

Thank you for your help. I’ll use the suggested approaches to manage that field.

This answer comes late, but this question pops high on Google, so I’ll add my finding here… seems to be OK per S. Graber, Found a way to add a Description to my LXC 5.1 containers from shell · Issue #11062 · lxc/lxd · GitHub

This works:

lxc config show abcd > container_abcd
sed -i 's/description: ""/description: "This works"/' container_abcd
lxc config edit abcd < container_abcd

Enjoy!

You can also do this in place with yq:

lxc config show abcd | yq '.devices.somedisk.readonly = true' | lxc config edit abcd
lxc config show abcd | yq '.description = "Some Description"' | lxc config edit abcd