LXC – is a good solution to get a stateful isolated environment.
Install
apt-get update
apt-get install lxd
Configure
- Before start:
lxd init
Confirm each question by default value. You can choose Name of the storage backend to use (btrfs, dir, lvm) [default=btrfs]: dir
to save files in a directories instead of lvm or image. It’s better to sync files.
- List remote repositories. Ensure that you have an external URLs.
lxc remote list
+-----------------+------------------------------------------+---------------+-----------+--------+--------+
| NAME | URL | PROTOCOL | AUTH TYPE | PUBLIC | STATIC |
+-----------------+------------------------------------------+---------------+-----------+--------+--------+
| images | https://images.linuxcontainers.org | simplestreams | | YES | NO |
- List images in repo:
lxc image list images:
You can grep
any images that you prefer. For example:
lxc image list images: | grep 'ubuntu.*18.04.*amd64'
Start
- Launch an image called
ubuntu01
from templateubuntu/18.04
:
lxc launch images:ubuntu/18.04 ubuntu01
- List running containers:
lxc list
- Enter into the container:
lxc exec ubuntu01 -- /bin/bash
So now you can work inside your new container. You can install and configure apps, etc.
If you are using a dir
as a storage backend, you can access to container files here: /var/lib/lxd/containers/
Modify
- Attach drive:
lxc config device add ubuntu01 srv disk source=/mnt/storage/srv/data/ path=/srv
- Run privileged (root=root) without uid shifting to 100000 :
lxc config set ubuntu01 security.privileged true
- Configure net for lxdbr0:
lxc network show lxdbr0
lxc network set lxdbr0 ipv4.address 10.10.107.1/24
or create a new one:
lxc network create lxdbr0 ipv6.address=none ipv4.address=10.0.3.1/24 ipv4.nat=true
assign an IP address for a container:
lxc network attach lxdbr0 ubuntu01 eth0
lxc config device set ubuntu01 eth0 ipv4.address 10.10.107.123