How to install and setup LXC Containers (OpenVZ alternative) on Centos 6 / 7

 

If you don't aleady have it, you'll need EPEL

Install LXC

yum -y install lxc lxc-templates
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirror.it.ubc.ca
 * epel: mirrors.kernel.org
 * extras: mirror.it.ubc.ca
 * updates: mirror.it.ubc.ca
Resolving Dependencies
--> Running transaction check
---> Package lxc.x86_64 0:1.0.11-1.el6 will be installed
--> Processing Dependency: lua-lxc(x86-64) = 1.0.11-1.el6 for package: lxc-1.0.11-1.el6.x86_64
--> Processing Dependency: lua-alt-getopt for package: lxc-1.0.11-1.el6.x86_64
--> Processing Dependency: liblxc.so.1()(64bit) for package: lxc-1.0.11-1.el6.x86_64
--> Running transaction check
---> Package lua-alt-getopt.noarch 0:0.7.0-1.el6 will be installed
---> Package lua-lxc.x86_64 0:1.0.11-1.el6 will be installed
--> Processing Dependency: lua-filesystem for package: lua-lxc-1.0.11-1.el6.x86_64
---> Package lxc-libs.x86_64 0:1.0.11-1.el6 will be installed
--> Running transaction check
---> Package lua-filesystem.x86_64 0:1.4.2-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                      Arch                                 Version                                     Repository                          Size
========================================================================================================================================================================
Installing:
 lxc                                          x86_64                               1.0.11-1.el6                                epel                               124 k
Installing for dependencies:
 lua-alt-getopt                               noarch                               0.7.0-1.el6                                 epel                               6.9 k
 lua-filesystem                               x86_64                               1.4.2-1.el6                                 epel                                24 k
 lua-lxc                                      x86_64                               1.0.11-1.el6                                epel                                16 k
 lxc-libs                                     x86_64                               1.0.11-1.el6                                epel                               257 k

Transaction Summary
========================================================================================================================================================================
Install       5 Package(s)

Total download size: 429 k
Installed size: 953 k
Downloading Packages:
(1/5): lua-alt-getopt-0.7.0-1.el6.noarch.rpm                                                                                                     | 6.9 kB     00:00    
(2/5): lua-filesystem-1.4.2-1.el6.x86_64.rpm                                                                                                     |  24 kB     00:00    
(3/5): lua-lxc-1.0.11-1.el6.x86_64.rpm                                                                                                           |  16 kB     00:00    
(4/5): lxc-1.0.11-1.el6.x86_64.rpm                                                                                                               | 124 kB     00:00    
(5/5): lxc-libs-1.0.11-1.el6.x86_64.rpm                                                                                                          | 257 kB     00:00    
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   554 kB/s | 429 kB     00:00    
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : lxc-libs-1.0.11-1.el6.x86_64                                                                                                                         1/5
  Installing : lua-filesystem-1.4.2-1.el6.x86_64                                                                                                                    2/5
  Installing : lua-lxc-1.0.11-1.el6.x86_64                                                                                                                          3/5
  Installing : lua-alt-getopt-0.7.0-1.el6.noarch                                                                                                                    4/5
  Installing : lxc-1.0.11-1.el6.x86_64                                                                                                                              5/5
  Verifying  : lua-alt-getopt-0.7.0-1.el6.noarch                                                                                                                    1/5
  Verifying  : lxc-libs-1.0.11-1.el6.x86_64                                                                                                                         2/5
  Verifying  : lxc-1.0.11-1.el6.x86_64                                                                                                                              3/5
  Verifying  : lua-filesystem-1.4.2-1.el6.x86_64                                                                                                                    4/5
  Verifying  : lua-lxc-1.0.11-1.el6.x86_64                                                                                                                          5/5

Installed:
  lxc.x86_64 0:1.0.11-1.el6                                                                                                                                            

Dependency Installed:
  lua-alt-getopt.noarch 0:0.7.0-1.el6         lua-filesystem.x86_64 0:1.4.2-1.el6         lua-lxc.x86_64 0:1.0.11-1.el6         lxc-libs.x86_64 0:1.0.11-1.el6       

Complete!

Create your first container!

Let's check the available templates first:

ls /usr/share/lxc/templates/
lxc-altlinux   lxc-busybox  lxc-cirros  lxc-download  lxc-gentoo        lxc-opensuse  lxc-plamo  lxc-ubuntu
lxc-alpine  lxc-archlinux  lxc-centos   lxc-debian  lxc-fedora    lxc-openmandriva  lxc-oracle    lxc-sshd   lxc-ubuntu-cloud

We use the lxc-create command, the relevant parts below are as follows:

-n = the name of the container

-t = template type (so if we see lxc-debian) we would type "debian"

-r = release (in Debian there is wheezy, sid, stretch etc..) that correspond to specific versions

-a = architecture (most commonly amd64 for 64bit or i386 for 386)

-p = the path this is optional but if you want it somewhere else like /mnt/sdb1 you would use this flag

lxc-create -n realtechtalk.com -t debian -- -r stretch -a amd64
/usr/share/lxc/templates/lxc-debian: line 574: type: debootstrap: not found
'debootstrap' command is missing
lxc_container: lxccontainer.c: create_run_template: 1092 container creation template for mywheezy failed
lxc_container: lxc_create.c: main: 274 Error creating container mywheezy
-bash-4.1# lxc-create -n realtechtalk.com -t debian -- -r stretch -a amd64
/usr/share/lxc/templates/lxc-debian: line 574: type: debootstrap: not found
'debootstrap' command is missing
lxc_container: lxccontainer.c: create_run_template: 1092 container creation template for realtechtalk.com failed
lxc_container: lxc_create.c: main: 274 Error creating container realtechtalk.com

Oops, we have a debootstrap missing command error.  For Debian machines we need debootstrap:

yum -y install debootstap

Try again:

lxc-create -n realtechtalk.com -t debian -- -r stretch -a amd64 -p /mnt/sdb1/
debootstrap is /usr/sbin/debootstrap
Checking cache download in /var/cache/lxc/debian/rootfs-stretch-amd64 ...
gpg: key 2B90D010: "Debian Archive Automatic Signing Key (8/jessie) <ftpmaster@debian.org>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
Downloading debian minimal ...
I: Retrieving InRelease
I: Retrieving Release
I: Retrieving Release.gpg
I: Checking Release signature
I: Valid Release signature (key id 126C0D24BD8A2942CC7DF8AC7638D0442B90D010)
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Checking component main on http://deb.debian.org/debian...
^[[6~

I: Retrieving libacl1 2.2.52-3+b1
I: Validating libacl1 2.2.52-3+b1
I: Retrieving adduser 3.115
I: Validating adduser 3.115
I: Retrieving libapparmor1 2.11.0-3+deb9u2
...........

............


Tags:

install, lxc, containers, openvz, centos, aleady, ll, epel, yum, plugins, fastestmirror, loading, speeds, cached, hostfile, ubc, ca, mirrors, kernel, org, extras, updates, resolving, dependencies, transaction, _, installed, processing, dependency, lua, alt, getopt, liblxc, noarch, filesystem, libs, resolution, resolved, repository, installing, summary, download, downloading, packages, rpm, kb, rpm_check_debug, succeeded, verifying, container,

Latest Articles

  • ssh Too many authentication failures not prompting for password
  • LightDM Mint Ubuntu Debian won't start errors Nvidia Graphics
  • WARNING: Unable to determine the path to install the libglvnd EGL vendor library config files. Check that you have pkg-config and the libglvnd development libraries installed, or specify a path with --glvnd-egl-config-path. Linux Ubuntu Mint Debian E
  • How To Upgrade Linux Mint 18.2 to 18.3 to 19.x and 20.x
  • MP3s Won't Play / ID3 Version 2.4 Issues in Cars and Other MP3 Players/CDs/DVDs Solution
  • LXC Containers LXD How to Install and Configure Tutorial Ubuntu Debian Mint
  • GlusterFS HowTo Tutorial For Distributed Storage in Docker, Kubernetes, LXC, KVM, Proxmox
  • Ubuntu Mint audio output not working pulseaudio "pulseaudio[13710]: [pulseaudio] sink-input.c: Failed to create sink input: too many inputs per sink."
  • How To Shrink Dynamically Allocated VM QEMU KVM VMware Disk Image File
  • How To Enable Linux Swapfile Instead of Partition Ubuntu Mint Debian Centos
  • 404 Not Found [IP: 151.101.194.132 80] apt update Debian 11 Bullseye Solution The repository 'http://security.debian.org bullseye/updates Release' does not have a Release file.
  • WARNING: Can't download daily.cvd from db.local.clamav.net freshclam clamav error solution
  • (firefox:9562): LIBDBUSMENU-GLIB-WARNING **: Unable to get session bus: Failed to execute child process "dbus-launch" (No such file or directory) Solution
  • Debian Mint Ubuntu Which Package Provides missing top, ps and w Solution
  • Vbox Virtualbox DNS NAT Network Mode NOT working
  • Docker Tutorial HowTo Install Docker, Use and Create Docker Container Images Clustering Swarm Mode Monitoring Service Hosting Provider
  • Zoom Password Error 'That passcode was incorrect' - Solution Wrong Passcode Wrong Meeting Name
  • How To Startup and Open Remote/Local Folder/Directory in Ubuntu Linux Mint automatically upon login
  • How To Reset Windows Server Password 2019, 2022, 7, 8, 10, 11 Recovery and Removal Guide Using Linux Ubuntu Mint Debian
  • How To Create OpenVPN Server for Secure Remote Corporate Access in Linux Debian/Mint/Ubuntu with client public key authentication