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
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 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>
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|