LXC : Install2026/05/07 |
|
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 [ubuntu2604] container root@dlp:~# lxc-create --name ubuntu2604 --template download -- --dist ubuntu --release resolute --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 resolute amd64 (20260502_07:43) 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 ubuntu2604 # display container information root@dlp:~# lxc-info -n ubuntu2604 Name: ubuntu2604 State: STOPPED # start containers as daemons root@dlp:~# lxc-start -n ubuntu2604 -d lxc-info -n ubuntu2604 Name: ubuntu2604 State: RUNNING PID: 2786 IP: fc42:5009:ba4b:5ab0:4481:e1ff:fe96:b5e8 Link: vethMubY2l TX bytes: 1.08 KiB RX bytes: 822 bytes Total bytes: 1.89 KiB # Connect to the container root@dlp:~# lxc-attach -n ubuntu2604
root@ubuntu2604:~# # connected to the container's shell
# to return to the host console, press [Ctrl + d] root@ubuntu2604:~# exit root@dlp:~# # To stop the container, do the following root@dlp:~# lxc-stop -n ubuntu2604
|
| [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 May 6 06:57 ./ drwxr-xr-x 49 root root 4096 May 6 06:55 ../ drwxrwx--- 3 root root 4096 May 6 06:58 ubuntu2604/ # 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 ubuntu2604 # take a snapshot of a container root@dlp:~# lxc-snapshot -n ubuntu2604 lxc-snapshot: ubuntu2604: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4129 Snapshot of directory-backed container requested lxc-snapshot: ubuntu2604: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4130 Making a copy-clone. If you do want snapshots, then lxc-snapshot: ubuntu2604: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4131 please create overlay clone first, snapshot that lxc-snapshot: ubuntu2604: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4132 and keep the original container pristine
root@dlp:~#
lxc-snapshot -n ubuntu2604 --list snap0 (/var/lib/lxc/ubuntu2604/snaps) 2026:05:06 07:04:27 # restore from snapshot root@dlp:~# lxc-snapshot -n ubuntu2604 -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 ubuntu2604 -d root@dlp:~# lxc-info -n ubuntu2604 | grep IP IP: fc42:5009:ba4b:5ab0:d4e8:2eff:fe62:f18a |
| Sponsored Link |
|
|