LXC image export does not export the correct METADATA.YML


I create lxc images automaticaly using the script that I made:

recently I discovered a problem with the export command of lxc and metadata. I modify the image metadata after creation for image versioning.

I use this command to export the image to a tar file

lxc image export django-server .

it creates a tar file with the fingerprint of the image. However when I open the tar and check the metadata.yml, It seems to be that the base image metadata is placed in the yml file rather than what is edited with LXC. I discovered that it does not match with the details on what I see with the following command:

lxc image info django-server

Why is there a mismatch? If requested I can create a bash script replicating this issue.

@stgraber is this by design or a bug?

That’s by design.

Images are immutable. You can override the database records of it, but the image itself cannot be mutated from the time it’s generated.

That’s because the image identifier is the SHA256 of the metadata+data combined. If we were allowing modifications in the database to affect the image, its exported fingerprint would no longer match.

Also, the same image (fingerprint) can be used by any number of projects and each project can alter properties in the database.

You normally should make sure all properties are set prior to publish your instance as an image, that can be done through lxc config metadata and lxc config templates.

If you want to export and restore an image using what’s been modified in the DB after its publication, your best bet is to use:

  • lxc image export HASH
  • lxc image show HASH > HASH.yaml

And then:

  • lxc image import HASH
  • lxc image edit HASH < HASH.yaml

Thanks a lot for the awesome support. By following your recommendation I managed to automatically populate the info for my container and then create an image of it. Here is what I did if anyone needs it.

cat build/temp-container-metadata.yaml | lxc config metadata edit ${CONTAINER_NAME}
lxc snapshot ${CONTAINER_NAME} current
lxc publish ${CONTAINER_NAME}/current --alias "django-server"