I installed lxd to use linux containers. For some reason I keep using lxc commands to install and start my containers. Since lxd seems to be close to lxc maybe there is a reason for that (but it is not clear).

I wanted to bind two lxc containers to two different bridges, different from the default lxcbr0 one. I created br1 and br2 and gave them IP addresses. They work fine and are pingable.

I am now trying to locate the place where I should change the configuration of my containers (cont1 and cont2) in order to have their eth0 (the interface name can be kept the same for each of those guests) bound to respectively br1 and br2.

The documentation states that

Then, specify the host's bridge in the container configuration file in place of lxcbr0, for instance

Where is this configuration file?

At the top of this documentation page, there is information about configuration files:

The following configuration files are consulted by LXC. For privileged use, they are found under /etc/lxc, while for unprivileged use they are under ~/.config/lxc.

lxc.conf may optionally specify alternate values for several lxc settings, including the lxcpath, the default configuration, cgroups to use, a cgroup creation pattern, and storage backend settings for lvm and zfs.

default.conf specifies configuration which every newly created container should contain. This usually contains at least a network section, and, for unprivileged users, an id mapping section

lxc-usernet.conf specifies how unprivileged users may connect their containers to the host-owned network.

lxc.conf and default.conf are both under /etc/lxc and $HOME/.config/lxc, while lxc-usernet.conf is only host-wide.

By default, containers are located under /var/lib/lxc for the root user, and $HOME/.local/share/lxc otherwise. The location can be specified for all lxc commands using the "-P|--lxcpath" argument.

If I read it correctly, it does not indicate where the container config file is.

The configuration I would like to add for cont1 is

lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br1
lxc.network.name = eth0
lxc.network.ipv4 =
lxc.network.ipv4.gateway =

and I tried to put it in the files /etc/lxc/cont1/config and /var/lib/lxc/cont1/config but none was taken into account: the container does not start, failing to bring up the networking. It works fine with the default config using lxcbr0.


Place configuration file for LXC container in any place and then specify this file when creating a container with -f option:

lxc-create {-n name} [-f config_file] {-t template} [-B backingstore] [-- template-options]  

for example:

sudo lxc-create -t download -f /any/path/u1.container.conf -n u1 -- -d ubuntu -r xenial -a amd64

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.