14

I have a OpenVZ VPS, the operating system is CentOS 6, I try to install Docker, but Docker start error.

Starting cgconfig service: Error: cannot mount cpuset to /cgroup/cpuset: Invalid argument
/sbin/cgconfigparser; error loading /etc/cgconfig.conf: Cgroup mounting failed
Failed to parse /etc/cgconfig.conf or /etc/cgconfig.d      [FAILED]
Starting docker:                                           [  OK  ]
baoyz
  • 358
  • 1
  • 3
  • 8
  • Looks like `cgroups` module is not loaded. Maybe not installed?! However `docker` can still work without cgroups support. try to install and enable `cgroups': `sudo yum install libcgroup` and `sudo service cgconfig start`. now you should be able to access `cgroups` paths: `sudo ls -l /cgroup`. Restart docker service and see if it works. – Boynux Dec 27 '15 at 04:51

2 Answers2

30

Updated on Dec 2016. I tried not to duplicate @Alien Life Form answer but add more details.

Short answer:

In most cases OpenVZ hosting will use OpenVZ 6 with an outdated kernel which is incompatible with Docker.

Docker is only supported with OpenVZ 7 (based on 3.x kernel, see https://openvz.org/Docker_inside_CT_vz7 ) or with OpenVZ 6 with kernel version 042stab105.4 or newer (see https://openvz.org/Docker_inside_CT ).

Long answer:

Docker requires two features of Linux kernel in order to operate: control groups and namespaces. So you need a kernel with these features.

With OpenVZ you don't control your kernel, only the hosting company does. Most hosting companies will not collaborate and update the kernel, so if the kernel turns to be incompatible you are generally out of luck.

OpenVZ 7 is based on 3.10 kernels which support Docker out of the box, however I have not yet seen a OpenVZ 7 hosting - KVM seems to be the most popular virtualization with new low cost providers entering the market.

OpenVZ 6 is more common in older providers, and is based on a 2.6 kernel generally incompatible with Docker. However, OpenVZ kernels are not normal 2.6 kernels but have few features backported from 3.x kernels. So in fact kernel 042stab105.4 and later support the features Docker needs according to the official OpenVZ wiki (see @Alien Life Form answer).

The text below only applies to OpenVZ version 6.

If uname -a shows kernel 042stab105.4 or later - you can use Docker with some tweaks for mounting the required special filesystems.

If it's older and the company is willing to collaborate, they cannot install a mainline kernel, as it's incompatible with OpenVZ. They must install a special kernel with OpenVZ patches from https://openvz.org/Download/kernel . Preferably the latest stable version (which is 042stab120.11 at the time of the writing) but at least 042stab105.4 . By comparison, all OpenVZ hosts I have seen have something like 2.6.32-042stab075.2, which is not only incompatible with Docker, but also vulnerable. So you can try using vulnerability argument to coerce the support into upgrading :)

Another obvious but not always applicable solution is to move away from OpenVZ to a hosting with another virtualization technology such as Xen or KVM. However, it may be the case that mainline CentOS 6 kernel does not have the necessary features, so CentOS 6 could only be compatible with Docker when run with non-stock patched kernels. So you can consider moving to CentOS 7 too.

nponeccop
  • 13,527
  • 1
  • 44
  • 106
  • 1
    Apparently docker 1.10 was the last version which worked with this 2.6.32 kernel. Subsequent docker releases present an error like: Your Linux kernel version 2.6.32-042stab123.2 is not supported for running docker. Please upgrade your kernel to 3.10.0 or newer. – Mike Schroll May 22 '17 at 06:28
  • Thank you for a detailed answer! It helped me a lot. – Dmitriy Nov 28 '17 at 07:32
1

Old thread - however, the solution can be found by treating CentOS6 as if it were a debian wheezy in this link: https://openvz.org/Docker_inside_CT

Basically, in /etc/init.d/docker do:

prestart() {
# ALF   service cgconfig status > /dev/null
# ALF
# ALF    if [[ $? != 0 ]]; then
# ALF        service cgconfig start
# ALF    fi
mount -t tmpfs tmpfs /sys/fs/cgroup
mkdir /sys/fs/cgroup/freezer,devices
mount -t cgroup cgroup /sys/fs/cgroup/freezer,devices -o freezer,devices
mkdir /sys/fs/cgroup/cpu,cpuacct,cpuset
mount -t cgroup cgroup /sys/fs/cgroup/cpu,cpuacct,cpuset/ -o cpu,cpuacct,cpuset

}
Alien Life Form
  • 1,884
  • 1
  • 19
  • 27
  • my /etc/init.d/docker does not have a prestart() function. I guess I can add this function anywhere, but when is it called and where from? – srayner Feb 28 '19 at 08:06