Hostname inside the container is by default set to the container name. How can i override it when launching a container?
What is the use case here? Are you wanting to just change the hostname or the associated DNS too?
Actually i’m mostly interested in changing associated DNS I know i can change hostname using hostnamectl but i was wondering if there is some config i can pass to have it set automatically.
Also i failed to mention that the container is using ovn network.
What is the reason you can’t change the name of the instance to match the hostname you want?
I’m doing that right now, but i’m looking for a better way, so for example i could have same hostnames on separate networks. As container names must be globally unique i cannot have that right now.
You may be able to change the initial hostname using raw.lxc
instance setting, but certainly this won’t change the DNS record created in OVN. This is always done using the instance name, see here:
However the way you can get around this is to use LXD projects, as OVN networks can exist on a per project basis too (so you could have the same instance with the same IP inside multiple different projects and OVN networks and they wouldn’t conflict).
lxc project create foo1 -c features.networks=true
lxc project create foo2 -c features.networks=true
lxc network create myovn --project=foo1 --type=ovn
lxc network create myovn --project=foo2 --type=ovn
lxc init images:ubuntu/jammy c1 --project=foo1 -n myovn
lxc init images:ubuntu/jammy c1 --project=foo2 -n myovn