The other container solution

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

How to install it

sudo pacman -S lxd

Add your user to the lxd group in /etc/group and restart lxd

sudo systemctl restart lxd


Which remotes do i have

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


How to list images in a remote

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

Using lxd/lxc

Launching a container

Start a centos 7 image with name puppetserver

lxc launch images:centos/7 puppetserver

Start a ubuntu 20.04 image with name puppetclient

lxc launch ubuntu:20.04 puppetclient

Listing the containers

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         |
+--------------+---------+------------------------+------+-----------+-----------+

Entering the containers

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

Stopping and starting containers

Ok it seems easy, but just so it's written

lxc stop puppetserver

And to start againg

lxc start puppetserver

Deleting containers

Ok and to delete a container

Stop it first

lxc stop puppetserver

And then delete it

lxc delete puppetserver

Extra

Adding shared directory between host and container

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

Previous Post Next Post