Tuesday, May 11, 2021

LXC -- Linux Containers

 Reference:

https://www.youtube.com/watch?v=CWmkSj_B-wo


playlist: https://www.youtube.com/playlist?list=PL34sAs7_26wPfLNZ5NKoH0RKbTAWMlh2I


To check your OS kernel:

lsb_release -dirc


to check whether lxd installed.

dpkg -l | grep lxd


to check whether/where lxc command executables

which lxc

which lxd


To install lxc on ubuntu:

sudo apt install lxd

To check the status of the service:

sudo systemctl enable/start/status lxd


to add user to lxd group:

----------

to see group exists:

getent group lxd

to add user to group:

sudo gpasswd -a username lxd

id username

newgrp lxd


To initialize lxc:

----------------

lxd init -->all default options except select dir as storage backend

lxc remote list

lxc image list

lxc image list images: --->to list in the particular repo

lxc image list images:debian

lxc list


Frequent commands:

---------------------

uname -r -->kernel version

lxc launch ubuntu:16.04

lxc launch ubuntu:16.04 <name>

lxc stop <name>

lxc delete <name> --force --> if running

lxc copy <name1> <name2>

lxc move myubuntu myvm


lxc exec myvm bash

>free -m

>nproc

>uname -r

>ping anothervm.lxd


lxc exec myanotherubuntu su - ubuntu
lxc info myvm | less
pstree -p <pid>
lxc config show myvm | less
lxc profile list
lxc profile show default
lxc profile copy default custom
lxc launch ubuntu:16.04 mym2 --profile custom

No need to stop the linux container to set limits:
lxc config set myvm limits.memory 512MB

lxc profile edit custom
config:
 limits.memory: 512MB
 limits.cpu: 1

lxc launch ubuntu:16:04 myvm2 --profile custom



copy files:
lxc file push myfile myvm2/path_inside
lxc file pull myvm2/path_inside .

snapshot and restore:
for i in $(seq 5); do mkdir $i; done
lxc snapshot myvm2 snap1
lxc restore myvm2 snap1

nested containers:
lxc can be run inside these lxc containers.
But we need to set some settings.

lxc config set myvm2 security.privileged true
lxc config set myvm2 security.nesting true





No comments:

Post a Comment