LXC : Install2026/04/17 |
|
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. |
|
# install from EPEL [root@dlp ~]# dnf --enablerepo=epel -y install lxc lxc-templates
|
| [2] | Configure Bridge networking for Containers. Replace the interface name [enp1s0] for your own environment. |
|
# add bridge [lxcbr0] [root@dlp ~]# nmcli connection add type bridge autoconnect yes con-name lxcbr0 ifname lxcbr0 Connection 'br0' (ced3dbca-7cc3-41bd-a42c-86857ecd1f7f) successfully added. # set IP address for [lxcbr0] [root@dlp ~]# nmcli connection modify lxcbr0 ipv4.addresses 10.0.0.30/24 ipv4.method manual
# set Gateway for [lxcbr0] [root@dlp ~]# nmcli connection modify lxcbr0 ipv4.gateway 10.0.0.1
# set DNS for [lxcbr0] [root@dlp ~]# nmcli connection modify lxcbr0 ipv4.dns 10.0.0.10
# set DNS search base for [lxcbr0] [root@dlp ~]# nmcli connection modify lxcbr0 ipv4.dns-search srv.world
# remove the current interface [root@dlp ~]# nmcli connection del enp1s0
# add the removed interface again as a member of [lxcbr0] [root@dlp ~]# nmcli connection add type bridge-slave autoconnect yes con-name enp1s0 ifname enp1s0 master lxcbr0
[root@dlp ~]#
[root@dlp ~]# reboot
ip addr show lxcbr0
4: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 52:54:00:7e:d7:d1 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.30/24 brd 10.0.0.255 scope global noprefixroute lxcbr0
valid_lft forever preferred_lft forever
inet6 fe80::1b1e:cfb7:f4d7:aff6/64 scope link noprefixroute
valid_lft forever preferred_lft forever
|
| [3] | As an example, we will create a CentOS Trixie container. Various other OS templates are available besides CentOS, which can be viewed at the following URL. ⇒ https://images.linuxcontainers.org/ |
|
# create [centos9] container [root@dlp ~]# lxc-create --name centos9 --template download -- --dist centos --release 10-Stream --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 Centos 10-Stream x86_64 (20260416_07:08) container. # list containers [root@dlp ~]# lxc-ls centos9 # display container information [root@dlp ~]# lxc-info -n centos9 Name: centos9 State: STOPPED # start containers as daemons [root@dlp ~]# lxc-start -n centos9 -d lxc-info -n centos9 Name: centos9 State: RUNNING PID: 2416 Link: vethTQDwGw TX bytes: 1.43 KiB RX bytes: 852 bytes Total bytes: 2.27 KiB # Connect to the container [root@dlp ~]# lxc-attach -n centos9
[root@centos9 ~]# # connected to the container's shell
# to return to the host console, press [Ctrl + d] [root@centos9 ~]# exit [root@dlp ~]# # To stop the container, do the following [root@dlp ~]# lxc-stop -n centos9
|
| [4] | Here are some other basic operating instructions. |
|
# container you created is saved in the following location [root@dlp ~]# ll /var/lib/lxc total 0 drwxrwx---. 3 root root 34 Apr 17 08:45 centos9 # for example, create a container on [ubuntu2404] [root@dlp ~]# lxc-create --name ubuntu2404 --template download -- --dist ubuntu --release noble --arch amd64 [root@dlp ~]# lxc-start -n ubuntu2404 -d # run a specific command and display the results on the host console [root@dlp ~]# lxc-attach -n ubuntu2404 -- /bin/echo "Welcome to the LXC World!" Welcome to the LXC World! # delete a container [root@dlp ~]# lxc-stop -n ubuntu2404 [root@dlp ~]# lxc-destroy -n ubuntu2404 [root@dlp ~]# lxc-ls centos9 # take a snapshot of a container [root@dlp ~]# lxc-snapshot -n centos9 lxc-snapshot: centos9: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4129 Snapshot of directory-backed container requested lxc-snapshot: centos9: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4130 Making a copy-clone. If you do want snapshots, then lxc-snapshot: centos9: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4131 please create overlay clone first, snapshot that lxc-snapshot: centos9: ../src/lxc/lxccontainer.c: do_lxcapi_snapshot: 4132 and keep the original container pristine
[root@dlp ~]#
lxc-snapshot -n centos9 --list snap0 (/var/lib/lxc/centos9/snaps) 2026:04:17 09:09:52 # restore from snapshot [root@dlp ~]# lxc-snapshot -n centos9 -r snap0
|
| Sponsored Link |
|
|