md-notes/lxc.md

83 lines
2.3 KiB
Markdown
Raw Permalink Normal View History

2022-09-27 09:37:40 +02:00
# LXC
### Installation
On debian install it using __snap__ it is the preferred way.
### Initialization:
Follow [this](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-lxd-on-ubuntu-20-04) tutorial to set up **lxd**.
### Launch and list containers:
```bash
2022-09-27 09:49:19 +02:00
lxc launch ubuntu:22.04 <container-name>
2022-09-27 09:37:40 +02:00
lxc list
```
2022-09-27 09:49:19 +02:00
to stop a container:
2022-09-27 09:37:40 +02:00
```bash
2022-09-27 09:49:19 +02:00
lxc stop <container-name>
2022-09-27 09:37:40 +02:00
```
2022-09-27 09:49:19 +02:00
to delete a container:
2022-09-27 09:50:39 +02:00
```bash
lxc delete <container-name>
```
2022-09-27 09:37:40 +02:00
### Setup static ip for container:
```bash
2022-09-27 09:49:19 +02:00
lxc config device override <container-name> eth0
lxc config device set <container-name> eth0 ipv4.address <container-ip>
2022-09-27 09:37:40 +02:00
```
### Start a shell inside a container:
```
2022-09-27 09:49:19 +02:00
lxc shell <container-name>
2022-09-27 09:37:40 +02:00
```
2022-09-29 23:11:54 +02:00
### List available images:
```
lxc image alias list images:
lxc image alias list images: | grep -i arch
lxc image alias list images: | grep -i debian
lxc image alias list images: | grep -i fedora
```
2022-09-27 09:37:40 +02:00
### Exposing container to the public:
2022-09-27 09:50:39 +02:00
Todo, for now follow linked tutorial. Host it on your own.
2022-09-27 13:01:44 +02:00
### Running Docker inside lxc:
Firstly you need to create storage device:
```bash
lxc sorage create <volume-name> btrfs
lxc launch images:ubuntu/22.04 <container-name>
```
Then add this storage device to container:
```bash
lxc config device add <container-name> docker disk pool=<volume-name> source=<container-name> path=/var/lib/docker
```
Then set privileges for docker to have ability to call syscalls.
```bash
lxc config set <container-name> security.nesting=true security.syscalls.intercept.mknod=true security.syscalls.intercept.setxattr=true
lxc restart <container-name>
```
2022-11-20 13:51:42 +01:00
### Flags that lxc init takes, eg. CPU conf, RAM conf, Display conf
```bash
lxc launch images:ubuntu/22.04/desktop ubuntu --vm -c limits.cpu=4 -c limits.memory=4GiB --console=vga
```
2022-09-27 13:05:33 +02:00
or read [this](https://ubuntu.com/tutorials/how-to-run-docker-inside-lxd-containers#2-create-lxd-container) tutorial.
2022-09-27 13:01:44 +02:00
2022-10-09 10:20:26 +02:00
## Troubleshooting
2022-09-27 13:01:44 +02:00
2022-10-09 10:20:26 +02:00
### No ipv4 in container??
```bash
2022-11-19 14:24:35 +01:00
for ipt in iptables iptables-legacy ip6tables ip6tables-legacy; do $ipt --flush; $ipt --flush -t nat; $ipt --delete-chain; $ipt --delete-chain -t nat; $ipt -P FORWARD ACCEPT; $ipt -P INPUT ACCEPT; $ipt -P OUTPUT ACCEPT; done
systemctl restart --now snap.lxd.daemon
2022-10-09 10:20:26 +02:00
```
read [this](https://discuss.linuxcontainers.org/t/containers-do-not-have-outgoing-internet-access/10844/4) article.
2022-09-27 13:01:44 +02:00