Smart way to run post create scripts doing container initalization stuff

How can I run bash script immediately after creating LXC container but not every time container is starting? I want to execute post create bash script only once after I create container. I mean scripts for things like doing apt update, useradd, apt install something, sed. Is there a smart way to do it?

Most distributions in the image repository have a cloud-init version. I would add a cloud-init script to the instance profile. It will be executed when the instance first boots.

Here is a tutorial for how to use it with Incus.

How can I do it without cloud-init? I don’t want to use it

I recommend using cloud-init.

If you don’t want to use it, then you could copy the script to the instance after it has booted then run it.

You could write a bash script that automates the process.