Published image gets deleted when its stopped container is removed

I’m facing a strange behavior when creating images remotely from a running container using Packer and normal commands.
My scenario as follows:

  1. add remote lxd server using lxc remote add dev ...
  2. launch an image on the remote server using lxc launch <image> dev:c1
  3. stop remote container 'lxc stop dev:c1`
  4. publish an image from the stopped container lxc publish dev:c1 --alias c1-image
  5. image is created without an alias
  6. delete the stopped container

What happens is that the image is deleted automatically once the container is deleted in step 6
Also the image was created without an alias although it was defined in the command. This behavior happens only when using remote instance through https, but it works fine with local socket.

I’m using 3.21 on my arch linux and 3.0.3 on remote ubuntu 18.04, I tried updating to the latest snap 3.21 using candidate channel but also it didn’t work.

This issue raised when I was trying Packer lxd builder module to create some containers remotely on dev server as a backup to mine.

Hmm, so where do you expect the published image to be located?
On dev: or on local:?

You are brilliant, your question let me check my images and found that all the images that were published with the previous command are moved to my local: machine, so I changed the command to the following and everything worked :slight_smile:

lxc publish dev1:c1 dev1: --alias c1-image

Thanks so much for your help

This topic is resolved, but just for reference, I was trying to provision an LXC environment using Packer and Terraform inside a cloud VM to run k3s as a lightweight kubernetes distro with the minimum resources.
Packer is able to create the instance remotely with the launch command, but when it comes to the publish command it doesn’t recognize the : notation, so eventually the instance gets migrated to my local:

As a solution, I had to run a local script before every VM provisioning to set the default remote as :dev1 or whatever needed for every remote VM. That worked well with Packer. Terraform LXD provisioner is more advanced and has the concept of Remote LXD connections for instance creation but still not working the same during provisioning which I had to do over SSH for every LXC container.