LXC / LXD

lxd init
 
# list storage
lxc storage list
 
# add storage
# lxc profile device add default root disk path=/ pool=<pool-name>
 
# list containers
lxc list
 
# list all images
lxc image alias list ubuntu:
lxc image alias list ubuntu: '22.04'
 
# create container
lxc launch ubuntu:22.04 MyContainer
 
# get container info
lxc info MyContainer
 
# open container shell
lxc exec MyContainer bash
 
# run command in container
lxc exec MyContainer hostname
 
# stop container
lxc stop MyContainer
 
# start container
lxc start MyContainer
 
# restart container
lxc restart MyContainer
 
# rename container
lxc move MyContainer NewContainerName
 
# clone container
lxc copy MyContainer MyContainerClone
 
# push file
lxc file push /path/file MyContainer/path/file
 
# pull file
lxc file pull MyContainer/path/file /path/file
 
# edit file
lxc file edit MyContainer/path/file
 
# take snapshot
lxc snapshot MyContainer
 
# restore snapshot
lxc restore MyContainer snap0
 
# delete snapshot
lxc delete MyContainer/snap0
 
# create container from snapshot
lxc copy MyContainer/snap0 NewContainer
 
# rename snapshot
mxc move MyContainer/snap0 MyContainer/NewSnapName0
 
# allow access from lan
lxc config device add MyContainer eth0 nic nictype=bridged parent=br0 name=eth0
# first eth0 = container nic name
# br0 = bridge adapter
lxc config device remove MyContainer eth0