Where is the configuration file of a lxc container?
Solution 1
A bit late, but in case someone else is - like I was - searching for an answer to this "obvious" question:
The config file for a privileged container seems to be in /var/lib/lxc/${containerName}/config
.
Solution 2
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
Related videos on Youtube
WoJ
Updated on September 18, 2022Comments
-
WoJ over 1 year
I installed
lxd
to use linux containers. For some reason I keep usinglxc
commands to install and start my containers. Sincelxd
seems to be close tolxc
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 defaultlxcbr0
one. I createdbr1
andbr2
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
andcont2
) in order to have theireth0
(the interface name can be kept the same for each of those guests) bound to respectivelybr1
andbr2
.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
islxc.network.type = veth lxc.network.flags = up lxc.network.link = br1 lxc.network.name = eth0 lxc.network.ipv4 = 10.10.11.0/24 lxc.network.ipv4.gateway = 10.10.11.11
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 usinglxcbr0
.