LXC IP, domain name and recreating experiments

Hi.

I’m developing among other things a Capistrano file, where I have to put a server address: it could be an IP or a domain name.

The server is a LXC, but each time I recreate it, it changes the IP, so I have to update the Capistrano file.

Let’s say the LXC instance name is lxc-instance. By any change does LXD already have a dns so I can get the IP by a name like lxc-instance.lxd.localhost or something like that?

If not… is there a way to use the same IP always, each time I launch the container?

Thanks!

If you’re using a managed bridge, such as the default lxdbr0, then yes the instance’s IP is resolvable using <instance_name>.lxd when querying the DNS server running on the bridge’s IP.

See the dns.* settings at Bridge network - LXD documentation

1 Like

You are also able to indicate that a specific instance always be allocated the same IP by setting it on the NIC device config, e.g.

lxc config device override instance eth0 ipv4.address=n.n.n.n

See the ipv{n}.address settings at Instance configuration - LXD documentation

1 Like