lxc usage

lxc usage


list images in repo

lxc image list images:

list local images

lxc image list local:

create container from image

lxc init images:opensuse/15.3 $CONTAINERNAME

create vm from image

lxc init images:opensuse/15.3 $CONTAINERNAME --vm

create & run container from image

lxc launch images:opensuse/15.3 $CONTAINERNAME

create & run vm from image

lxc launch images:opensuse/15.3 $CONTAINERNAME --vm

delete container/vm

lxc stop $CONTAINERORVMNAME
lxc delete $CONTAINERORVMNAME
# or
lxc delete -f $CONTAINERORVMNAME

execute command in container

lxc exec $CONTAINERNAME /bin/$COMANDNAME

touch to container shell

lxc shell $CONTAINERNAME
# or
lxc exec $CONTAINERNAME /bin/bash

push file to containert

lxc file push /path/to/local/file $CONTAINERNAME/path/to/dir/in/container/

pull file from container

lxc file pull $CONTAINERNAME/path/to/file/in/container /path/to/local/dir/

list local container/vm

lxc ls

create snapshot

lxc snapshot $CONTAINERORVMNAME $SNAPSHOTNAME

list snapshots container/vm

lxc info $CONTAINERORVMNAME

restore container/vm to snapshot

lxc restore $CONTAINERORVMNAME $SNAPSHOTNAME

delete container/vm snapshot

lxc delete $CONTAINERORVMNAME/$SNAPSHOTNAME

mount directory from host to container

lxc config device add $CONTAINERNAME $SHARENAME $DEVICETYPE_disk source=/path/on/host path=/path/on/container/

delete shared host directory from container

lxc config device remove $CONTAINERNAME $SHARENAME

create container/vm backup:

# GZIP
lxc export $CONTAINERNAME /path/to/$BACKUPNAME.tar.gz --compression gzip
# or ZSTD
lxc export $CONTAINERNAME /path/to/$BACKUPNAME.tar.zst --compression zstd

restore container/vm backup:

lxc import /path/to/$BACKUPNAME.tar.gz

delete container backup:

lxc query -X DELETE /1.0/containers/$CONTAINERNAME/backups/$BACKUPNAME

resize root disk for lxd VM:

lxc config device override $VMNAME root size=15GB

forward port to host

lxc config device add $CONTAINERNAME $PORTNAME proxy connect="tcp:127.0.0.1:8123" listen="tcp:0.0.0.0:8123"

forward usb device from host to container

lxc config device add $CONTAINERNAME zgb_snff usb vendorid=$VENDORID productid=$PRODUCTID

allow tun/tap devices into container:

lxc config device add $CONTAINERNAME tun unix-char path=/dev/net/tun

restrict container/vm by resources

lxc config set $CONTAINERORVMNAME limits.memory $MEMORYLIMITSIZE
lxc config set $CONTAINERORVMNAME limits.cpu $VCPUCORELIMIT

set autostart

lxc config set $CONTAINERORVMNAME boot.autostart $TRUEORFALSE
lxc config set $CONTAINERORVMNAME boot.autostart.priority $PRIORITY
lxc config set $CONTAINERORVMNAME boot.autostart.delay $DELAYINSECONDS

open virtual display vm

lxc console $VMNAME --type=vga

Содержание