meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
linux:lxc [2016/04/18 10:39] – [Network] niziak | linux:lxc [2020/09/07 19:01] (current) – niziak | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== LXC ====== | ====== LXC ====== | ||
- | * /var/lib/lxc default container place | + | * LXC web panel: [[https://lxc-webpanel.github.io/index.html]] |
- | * / | + | |
===== Preparation ===== | ===== Preparation ===== | ||
<code bash> | <code bash> | ||
sudo apt-get install bridge-utils | sudo apt-get install bridge-utils | ||
- | sudo apt-get install lxc lxc-templates cgmanager cgroup-lite | + | sudo apt-get install lxc lxc-templates |
+ | sudo apt-get install | ||
sudo lxc-checkconfig | sudo lxc-checkconfig | ||
</ | </ | ||
+ | |||
Make sure cgroup filesystem is mounted | Make sure cgroup filesystem is mounted | ||
+ | |||
<file | / | <file | / | ||
cgroup / | cgroup / | ||
</ | </ | ||
- | ===== Basic usage ===== | + | ===== LXC Files ==== |
+ | ==== Priviledged containers ==== | ||
+ | * / | ||
+ | * / | ||
+ | |||
+ | ==== Unpriviledged containers ==== | ||
+ | |||
+ | <code text> | ||
+ | /home/user | ||
+ | ├── .cache | ||
+ | │ ├── lxc | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | ├── .config | ||
+ | │ └── lxc | ||
+ | │ | ||
+ | ├── .local | ||
+ | │ └── share | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | </ | ||
+ | |||
+ | ===== Basic usage ===== | ||
<code bash> | <code bash> | ||
lxc-create -n test-container -t ubuntu | lxc-create -n test-container -t ubuntu | ||
+ | lxc-create -n test-container -t ubuntu -B btrfs | ||
+ | lxc-create -n test-container -t download -B btrfs | ||
+ | lxc-destroy -n test-container | ||
+ | |||
lxc-start -n test-container | lxc-start -n test-container | ||
lxc-start -n test-container --daemon | lxc-start -n test-container --daemon | ||
- | lxc-info -n test-container | ||
- | lxc-attach -n test-container | ||
- | lxc-console -n test-container | ||
lxc-stop -n test-container | lxc-stop -n test-container | ||
- | lxc-destroy -n test-container | ||
- | </ | ||
- | ==== Getting info ==== | ||
- | <code bash> | ||
lxc-ls --fancy | lxc-ls --fancy | ||
lxc-info -n test-container | lxc-info -n test-container | ||
+ | |||
+ | lxc-attach -n test-container | ||
+ | lxc-console -n test-container | ||
+ | |||
+ | lxc-snapshot -n test-container | ||
</ | </ | ||
+ | |||
+ | |||
+ | ==== Bind mounts ==== | ||
+ | <file | local/ | ||
+ | lxc.mount.entry = / | ||
+ | </ | ||
===== Templates ===== | ===== Templates ===== | ||
Line 85: | Line 145: | ||
Edit container configuration and set net bridge interface: | Edit container configuration and set net bridge interface: | ||
< | < | ||
+ | |||
+ | |||
+ | |||
+ | ===== Unprivileged containers ===== | ||
+ | Create user: | ||
+ | <code bash> | ||
+ | <code bash> | ||
+ | |||
+ | Find subuids and subgids for created user | ||
+ | <code bash> | ||
+ | < | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Allow new user create network interfaces: | ||
+ | <file | / | ||
+ | lxcgitlab veth br0 10 | ||
+ | </ | ||
+ | |||
+ | Now login as new user (using ssh or su). | ||
+ | Create default lxc configureation in user directory: | ||
+ | <code bash> | ||
+ | mkdir -p ~/ | ||
+ | cp / | ||
+ | </ | ||
+ | |||
+ | Edit file below and put subuid and subgid: | ||
+ | <file | ~/ | ||
+ | ... | ||
+ | lxc.network.link = br0 | ||
+ | lxc.id_map = u 0 165536 65536 | ||
+ | lxc.id_map = g 0 165536 65536 | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Create container: | ||
+ | <code bash> | ||
+ | |||
+ | ==== Snapshot ==== | ||
+ | |||
+ | ~$ lxc-snapshot -n gitlab | ||
+ | newgidmap: gid range [165536-165537) -> [331072-331073) not allowed | ||
+ | error mapping child | ||
+ | setgid: Invalid argument | ||
+ | |||
+ | lxc-snapshow is calling '' | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | ==== Autostart ==== | ||
+ | |||
+ | <file | ~/ | ||
+ | lxc.start.auto = 1 | ||
+ | lxc.start.delay = 5 | ||
+ | lxc.start.order = 100 | ||
+ | lxc.group = onboot | ||
+ | </ | ||
+ | < | ||
+ | lxc-autostart | ||
+ | tering by lxc.group or just run against all defined containers. It can also be used by external tools in list mode where no action will be performed and the list of affected con‐ | ||
+ | tainers (and if relevant, delays) will be shown. | ||
+ | </ | ||
+ | |||
+ | Edit cron | ||
+ | <code bash> | ||
+ | < | ||
+ | |||
+ | |||
+ | Use systemd (**not finished yet**): | ||
+ | Enable autostarting systemd for user: | ||
+ | < | ||
+ | |||
+ | <file | ~/ | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | ===== Limit resources ===== | ||
+ | <file | config> | ||
+ | # 512MB memory limit, 256MB soft limie - system treats it as low mem condition | ||
+ | lxc.cgroup.memory.limit_in_bytes = 512M | ||
+ | lxc.cgroup.memory.soft_limit_in_bytes = 256M | ||
+ | # total usage memory (swap+ram) limit to 1G | ||
+ | lxc.cgroup.memory.memsw.limit_in_bytes = 1G | ||
+ | |||
+ | # arbitary value which only sets relative priority between containers | ||
+ | lxc.cgroup.cpu.shares = 100 | ||
+ | |||
+ | # restrict to use cpu core 0 and 1 | ||
+ | lxc.cgroup.cpuset.cpus 0,1 | ||
+ | |||
+ | lxc.cgroup.blkio.weight 500 | ||
+ | </ | ||
+ | |||
+ | Limiting runtime: | ||
+ | <code bash> | ||
+ | |||
+ | <file | ~/ | ||
+ | </ | ||
+ | ==== ulimit change for unpriv container ==== | ||
+ | Inside container, this command fails: | ||
+ | <code bash> | ||
+ | |||
Line 110: | Line 283: | ||
lxc-start 1460629578.159 ERROR lxc_start_ui - lxc_start.c: | lxc-start 1460629578.159 ERROR lxc_start_ui - lxc_start.c: | ||
</ | </ | ||
+ | |||
+ | Debug levels: '' | ||
+ | |||
+ | Configure debug levels in config file: | ||
+ | lxc.logfile | ||
+ | lxc.loglevel | ||
+ | |||
===== Errors ===== | ===== Errors ===== | ||
+ | |||
+ | ==== Failed to load config for gitlab ==== | ||
+ | |||
+ | Error after system upgrade. LXC has been updated from 2.0.1 to v 3.0.1 | ||
+ | |||
+ | <code bash> | ||
+ | $ lxc-info gitlab | ||
+ | Failed to load config for gitlab | ||
+ | Failure to retrieve information on / | ||
+ | </ | ||
+ | |||
+ | SOLUTION: | ||
+ | <code bash> | ||
+ | cd / | ||
+ | lxc-update-config -c config | ||
+ | </ | ||
+ | |||
==== Failed to mount cgroup ==== | ==== Failed to mount cgroup ==== | ||
< | < | ||
Line 162: | Line 359: | ||
systemctl restart lxc-net | systemctl restart lxc-net | ||
</ | </ | ||
+ | |||
+ | ==== umount: /dev/zero: block devices are not permitted on filesystem ==== | ||
+ | During shutdown | ||
+ | < | ||
+ | umount: /dev/zero: block devices are not permitted on filesystem | ||
+ | umount: / | ||
+ | umount: /dev/tty: block devices are not permitted on filesystem | ||
+ | </ | ||
+ | >Ah - this is happening because the shutdown process is trying to do a | ||
+ | >force umount. | ||
+ | >a bind mount from a fuse or nfs, it'll disconnect the original mount. | ||
+ | > | ||
+ | >You can test this yourself by logging in and doing | ||
+ | > | ||
+ | >umount -f / | ||
+ | > | ||
+ | >versus | ||
+ | > | ||
+ | >umount / | ||