Installing LXC on CentOS 7
-
First, let's make sure we have all the latest packages.
yum -y update
Now we can install LVX
yum install lxc lxc-templates libvirt
Start libvirtd
systemctl start libvirtd
Now let's create our first container
lxc-create -n <name> -t download Setting up the GPG keyring Downloading the image index --- DIST RELEASE ARCH VARIANT BUILD --- centos 6 amd64 default 20160311_02:16 centos 6 i386 default 20160311_02:16 centos 7 amd64 default 20160311_02:16 debian jessie amd64 default 20160311_22:42 debian jessie armel default 20160111_22:42 debian jessie armhf default 20160111_22:42 debian jessie i386 default 20160311_22:42 debian sid amd64 default 20160311_22:42 debian sid armel default 20160111_22:42 debian sid armhf default 20160111_22:42 debian sid i386 default 20160311_22:42 debian wheezy amd64 default 20160311_22:42 debian wheezy armel default 20160111_22:42 debian wheezy armhf default 20160111_22:42 debian wheezy i386 default 20160311_22:42 fedora 21 amd64 default 20160311_01:27 fedora 21 armhf default 20160112_01:27 fedora 21 i386 default 20160311_01:27 fedora 22 amd64 default 20160311_01:27 fedora 22 armhf default 20160112_01:27 fedora 22 i386 default 20160311_01:27 gentoo current amd64 default 20160311_14:12 gentoo current armhf default 20160111_14:12 gentoo current i386 default 20160311_14:12 oracle 6.5 amd64 default 20160311_11:40 oracle 6.5 i386 default 20160311_11:40 plamo 5.x amd64 default 20160311_21:36 plamo 5.x i386 default 20160311_21:36 ubuntu precise amd64 default 20160311_03:49 ubuntu precise armel default 20160112_03:49 ubuntu precise armhf default 20160311_03:49 ubuntu precise i386 default 20160311_03:49 ubuntu trusty amd64 default 20160311_03:49 ubuntu trusty armhf default 20160311_03:49 ubuntu trusty i386 default 20160311_03:49 ubuntu wily amd64 default 20160311_03:49 ubuntu wily armhf default 20160311_03:49 ubuntu wily i386 default 20160311_03:49 ubuntu xenial amd64 default 20160311_03:49 ubuntu xenial armhf default 20160311_03:49 ubuntu xenial i386 default 20160311_03:49 --- Distribution: centos Release: 7 Architecture: 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 container (release=7, arch=amd64, variant=default) To enable sshd, run: rc-update add sshd For security reason, container images ship without user accounts and without a root password. Use lxc-attach or chroot directly into the rootfs to set a root password or create user accounts.
Set your root password
[root@localhost ~]# chroot /var/lib/lxc/<name>/rootfs passwd Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully.
Start the container
lxc-start -d -n <name>
Attach to the container concole
lxc-attach -n <name>
Disconnect by tying exit.
echo "lxc.kmsg = 0" >> /usr/share/lxc/config/fedora.common.conf
-
last command should be
lxc-attach -n
-
Running a CentOS 7 LXC container using lxc-create CentOS 7 results in a 100% CPU loop for the systemd-journald process.
To fix this issue you must add lxc.kmsg = 0 to the container configuration. This can be done easily for all the CentOS 7 templates in one shot:
echo "lxc.kmsg = 0" >> /usr/share/lxc/config/fedora.common.conf
Here is the fix: http://vfamilyserver.org/blog/2015/03/fedora-21-lxc-systemd-journald-at-100/
-
Pretty minor it seems, just a config line was left out of the container creation script.
-
@scottalanmiller it seems like LXC is supported better on Ubuntu then CentOS 7. Do you think that's true?
-
@aaronstuder said:
@scottalanmiller it seems like LXC is supported better on Ubuntu then CentOS 7. Do you think that's true?
Very much so. Containers is a massive focus for Ubuntu and LXC is where they put all of their effort. They have gone to great lengths to be the container distro.
-
@scottalanmiller so maybe I should move to Ubuntu for the host.
-
@aaronstuder said:
@scottalanmiller so maybe I should move to Ubuntu for the host.
That might be an overration to the case. If you plan to containerize CentOS on top of it, I'd be pretty hesitant to move to Ubuntu underneath.
-
@scottalanmiller I'll stick to CentOS 7
-
Problem solved