LXC : Install2026/04/16 |
|
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 Ubuntu container. Various other OS templates are available besides Ubuntu, which can be viewed at the following URL. ⇒ https://images.linuxcontainers.org/ |
|
# create [ubuntu2404] container root@dlp:~# lxc-create --name ubuntu2404 --template download -- --dist ubuntu --release noble --arch amd64 Downloading the image index Downloading the rootfs Downloading the metadata The image cache is now ready Unpacking the rootfs --- You just created an Ubuntu noble amd64 (20260415_07:42) 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 ubuntu2404 # display container information root@dlp:~# lxc-info -n ubuntu2404 Name: ubuntu2404 State: STOPPED # start containers as daemons root@dlp:~# lxc-start -n ubuntu2404 -d lxc-info -n ubuntu2404 Name: ubuntu2404 State: RUNNING PID: 2111 IP: 10.0.3.86 Link: veth11jFiT TX bytes: 1.15 KiB RX bytes: 1.93 KiB Total bytes: 3.08 KiB # Connect to the container root@dlp:~# lxc-attach -n ubuntu2404
root@ubuntu2404:~# # connected to the container's shell
# to return to the host console, press [Ctrl + d] root@ubuntu2404:~# exit root@dlp:~# # To stop the container, do the following root@dlp:~# lxc-stop -n ubuntu2404
|
| [3] | Here are some other basic operating instructions. |
|
# container you created is saved in the following location root@dlp:~# ll /var/lib/lxc total 12 drwxr-xr-x 3 root root 4096 Apr 16 00:06 ./ drwxr-xr-x 46 root root 4096 Apr 16 00:05 ../ drwxrwx--- 3 root root 4096 Apr 16 00:08 ubuntu2404/ # 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 ubuntu2404 # take a snapshot of a container root@dlp:~# lxc-snapshot -n ubuntu2404
root@dlp:~#
lxc-snapshot -n ubuntu2404 --list snap0 (/var/lib/lxc/ubuntu2404/snaps) 2026:04:16 00:10:44 # restore from snapshot root@dlp:~# lxc-snapshot -n ubuntu2404 -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 00:16:3e: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 fe80::216:3eff:fe00:0/64 scope link
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 ubuntu2404 -d root@dlp:~# lxc-info -n ubuntu2404 | grep IP IP: 10.0.3.108 |
| Sponsored Link |
|
|