Install Docker on OpenVZ VPS

baoyz picture baoyz · Dec 26, 2015 · Viewed 20.2k times · Source

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  ]

Answer

nponeccop picture nponeccop · Mar 12, 2016

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.