Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Docker on OpenVZ VPS

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  ]
like image 482
baoyz Avatar asked Dec 26 '15 16:12

baoyz


People also ask

Can I run Docker on OpenVZ?

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 ).

How to install Docker on dedicated server?

Installing Docker Connect to your server via SSH with a privileged user (root). The first step is to update (list of packages) your server. This script will automatically detect your operating system, install the needed packages and install Docker. Then run the docker install command again.

What is Docker in Docker?

Running Docker inside Docker lets you build images and start containers within an already containerized environment. There are two possible approaches to achieve this depending on whether you want to start child or sibling containers.


2 Answers

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.

like image 113
nponeccop Avatar answered Sep 23 '22 13:09

nponeccop


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

}
like image 42
Alien Life Form Avatar answered Sep 21 '22 13:09

Alien Life Form