LXC : Install2026/04/15 |
|
Install the container-based virtualization software LXC (Linux Containers). Because it uses paravirtualization, which shares the host and kernel, other operating systems like Windows cannot be used. |
|
| [1] | Install LXC. |
|
root@dlp:~# apt -y install lxc
|
| [2] | As an example, we will create a Debian Trixie container. Various other OS templates are available besides Debian, which can be viewed at the following URL. ⇒ https://images.linuxcontainers.org/ |
|
# create [debian13] container root@dlp:~# lxc-create --name debian13 --template download -- --dist debian --release trixie --arch amd64 Downloading the image index Downloading the rootfs Downloading the metadata The image cache is now ready Unpacking the rootfs --- You just created a Debian trixie amd64 (20260414_05:24) container. To enable SSH, run: apt install openssh-server No default root or user password are set by LXC. # list containers root@dlp:~# lxc-ls debian13 # display container information root@dlp:~# lxc-info -n debian13 Name: debian13 State: STOPPED # start containers as daemons root@dlp:~# lxc-start -n debian13 -d lxc-info -n debian13 Name: debian13 State: RUNNING PID: 864 Link: vethXj33Q6 TX bytes: 592 bytes RX bytes: 722 bytes Total bytes: 1.28 KiB # Connect to the container root@dlp:~# lxc-attach -n debian13
root@debian13:~# # connected to the container's shell
# to return to the host console, press [Ctrl + d] root@debian13:~# exit root@dlp:~# # To stop the container, do the following root@dlp:~# lxc-stop -n debian13
|
| [3] | Here are some other basic operating instructions. |
|
# container you created is saved in the following location root@dlp:~# ll /var/lib/lxc total 4 drwxrwx--- 3 root root 4096 Apr 15 10:23 debian13 # for example, create a container on [centos10] root@dlp:~# lxc-create --name centos10 --template download -- --dist centos --release 10-Stream --arch amd64 root@dlp:~# lxc-start -n centos10 -d # run a specific command and display the results on the host console root@dlp:~# lxc-attach -n centos10 -- /bin/echo "Welcome to the LXC World!" Welcome to the LXC World! # delete a container root@dlp:~# lxc-stop -n centos10 root@dlp:~# lxc-destroy -n centos10 root@dlp:~# lxc-ls debian13 # take a snapshot of a container root@dlp:~# lxc-snapshot -n debian13 lxc-snapshot: debian13: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4125 Snapshot of directory-backed container requested lxc-snapshot: debian13: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4126 Making a copy-clone. If you do want snapshots, then lxc-snapshot: debian13: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4127 please create overlay clone first, snapshot that lxc-snapshot: debian13: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4128 and keep the original container pristine
root@dlp:~#
lxc-snapshot -n debian13 --list snap0 (/var/lib/lxc/debian13/snaps) 2026:04:15 10:40:11 # restore from snapshot root@dlp:~# lxc-snapshot -n debian13 -r snap0
|
| [4] | It is also possible to access containers running as daemons via HTTP or SSH. |
|
# bridge network is configured on the host side root@dlp:~# ip address show lxcbr0
4: lxcbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 10:66:6a:00:00:00 brd ff:ff:ff:ff:ff:ff
inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0
valid_lft forever preferred_lft forever
inet6 fc42:5009:ba4b:5ab0::1/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::1266:6aff:fe00:0/64 scope link proto kernel_ll
valid_lft forever preferred_lft forever
# Check the container's IP address # you can access the container by accessing the displayed IP address via HTTP or SSH root@dlp:~# lxc-start -n debian13 -d root@dlp:~# lxc-info -n debian13 | grep IP IP: 10.0.3.204 IP: fc42:5009:ba4b:5ab0:ccc6:1eff:fe3e:8ec9 |
| Sponsored Link |
|
|