Problems setting up LXC
-
- Offline
- 1 year 1 month ago
- 2017-02-25
Hi! I just discovered Alpine Linux and after a bit of noodling around and reading, I have fallen in love with this distro. I'm setting up a project right now that I want to utilize LXC/LXD containers. I see LXD is in the testing repos (which is no big deal to me), but I can't find anything on setting it up. lxd init fails. So I tried to do LXC, and following the instructions proves unfruitful.
https://wiki.alpinelinux.org/wiki/LXC
I can create containers if I don't include the lxc.conf file for networking, but then I don't have networking. Otherwise anything else I try I get these errors:
lxc-start: tools/lxc_start.c main: 360 The container failed to start.
lxc-start: tools/lxc_start.c: main: 362 To get more details, run the container in foreground mode.
lxc-start: tools/lxc_start.c: main: 364 Additional information can be obtained by setting the --logfile and --logpriority options.
So I tried adding --logfile and got this information:
lxc-start 20170224153317.003 ERROR lxc_cgfs - cgroups/cgfs.c:do_setup_cgroup_limits:2037 - No such file or directory - Error setting use to @kernel for test1
lxc-start 20170224153317.003 ERROR lxc_start - start.c:lxc_spawn:1182 - Failed to setup cgroup limits for container "test1".
lxc-start 20170224153317.033 ERROR lxc_start - start.c:__lxc_start:1338 - Failed to spawn container "test1".
lxc-start 20170224153322.075 ERROR lxc_start_ui - tools/lxc_start.c:main:360 - The container failed to start.
lxc-start 20170224153322.076 ERROR lxc_start_ui - tools/lxc_start.c:main:362 - To get more details, run the container in foreground mode.
lxc-start 20170224153322.076 ERROR lxc_start_ui - tools/lxc_start.c:main:364 - Additional information can be obtained by setting the --logfile and --logpriority options.
How do I get this working as it should?
Yo I'd been having some problems myself for a script I am making. Just ironed everything out tonight at 6am.
I don't really know what's wrong with your setup, but the way you worded it leads me to believe that the issue might be in which configuration files you're using:
lxc.conf and default.conf (or whatever conf you're using to make your container) aren't interchangeable, as far as I know.
http://man7.org/linux/man-pages/man5/lxc.conf.5.html
lxc.conf is for the program itself; you can specify the dir in which lxc looks for containers, such as changing it from /var/lib/lxc to /lxc/containers, or whatever. Must stay named /etc/lxc/lxc.conf.
https://linuxcontainers.org/lxc/manpages/man5/lxc.system.conf.5.html
default.conf is a configuration file for the individual containers. Can be renamed to anything when the path is specified by lxc-create's -f option.
https://linuxcontainers.org/lxc/manpages/man5/lxc.container.conf.5.html
(The name scheme of these web pages is a little misleading. It appears lxc.conf.5.html is a general summary of the config files, lxc.system.conf.5.html is the 'lxc.conf,' and lxc.container.conf.5.html is what I am referring to as 'default.conf.')
LXC is really picky about its configuration files. If there's an option spelled wrong, it might not even tell you which option it is; never mind adding options for lxc.conf rather than the default.conf. Sometimes you'll just get error 318 with no explanation. I'm still having nightmares.
Using this line:
lxc-create -n files -f /var/lib/lxc/files/config -t alpine
here is a working config which I use:
Also, setting the --logpriority (-o) to "trace" gives more details than error, which is the default I think.
The biggest problem for myself was figuring out exactly where my filesystems needed to be. They can barely be moved from /var/lib/lxc. Its best to let most directory names/locations stay default, and create a new directory while organising with symlinks.
For my overlayfs setup it's kinda like this:
For non-overlayfs setup you'd just change delta0 to rootfs, i think.
I have a script that makes my containers for me in this manner.
I feel like some of the documentation is incomplete, or that certain bits of information are buried a little too deep.