Normaly we only think about docker containers if we want to containerize something in linux. But there are more options lxd/lxc is one of those other solutions.
Where docker containers are mostly used to start one process, lxd containers are more like containerized vm's
sudo pacman -S lxd
or
sudo apt install lxd-installer
or
sudo snap install lxd --channel=latest/stable
Add your user to the lxd group in /etc/group and restart lxd
sudo systemctl restart lxd
lxc remote list
> lxc remote list
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| NAME | URL | PROTOCOL | AUTH TYPE | PUBLIC | STATIC | GLOBAL |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| images | https://images.linuxcontainers.org | simplestreams | none | YES | NO | NO |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| local (current) | unix:// | lxd | file access | NO | YES | NO |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| ubuntu | https://cloud-images.ubuntu.com/releases | simplestreams | none | YES | YES | NO |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
| ubuntu-daily | https://cloud-images.ubuntu.com/daily | simplestreams | none | YES | YES | NO |
+-----------------+------------------------------------------+---------------+-------------+--------+--------+--------+
~ >
You can add remotes with lxc remote add
lxc image list images:
Where images: is de remote name
lxc image list ubuntu:
List local images
lxc image list
And remove local image, clean up space with
lxc image delete
Start a oracle 9 image with name puppetserver
lxc launch images:oracle/9 puppetserver
Start a ubuntu 20.04 image with name puppetclient
lxc launch ubuntu:22.04 puppetclient
lxc list
> lxc list
+--------------+---------+------------------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------------+---------+------------------------+------+-----------+-----------+
| puppetserver | RUNNING | 192.168.211.49 (eth0) | | CONTAINER | 0 |
+--------------+---------+------------------------+------+-----------+-----------+
| puppetclient | RUNNING | 192.168.211.118 (eth0) | | CONTAINER | 0 |
+--------------+---------+------------------------+------+-----------+-----------+
lxc exec puppetserver -- /bin/bash
[root@puppetserver ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core)
Or entering with a login profile
lxc exec puppetserver -t -- /bin/su --login
Ok it seems easy, but just so it's written
lxc stop puppetserver
And to start againg
lxc start puppetserver
Ok and to delete a container
Stop it first
lxc stop puppetserver
And then delete it
lxc delete puppetserver
Make a directory to share
sudo mkdir /opt/share
Change the lxc config for the container
lxc config edit puppetserver
Add a line to the config: section
config:
raw.lxc: lxc.mount.entry = /opt/share opt/share none bind,create=dir 0.0
And restart the container
lxc restart puppetserver
And your shared directory is there, still need to look into mapping of uid how that is best done
You can also change the config with this command
lxc config set puppetserver raw.lxc='lxc.mount.entry = /opt/share opt/share none bind,create=dir 0.0'
a solution for the mapping can maybe be found on askubuntu
rsync -avP -e "sh -c 'lxc exec \"\$0\" -- \"\$@\"'" local_dir/ container-name:/root/remote_dir/
Fix firewall so that dhcp works
sudo ufw allow in on lxdbr0
Still need to fix the forwarding.