How is this possible? CentOS container on Ubuntu (newbie question)

I’m a newbie to Docker and Linux. Following this training and many others I see that you can run a “centos” container on a Ubuntu Linux OS.

How is this possible? The way I am seeing containers would contain applications and its dependencies. Please explain how is it that a container runs another OS?



The docker server runs on any Linux os. E.g. I installed docker on an Ubuntu 16.04 machine:

$ docker info
Server Version: 1.12.1
Storage Driver: overlay2
Kernel Version: 4.4.0-31-generic
Operating System: Ubuntu 16.04.1 LTS

Now I can create a container from any image. Remember docker image can be based on (Dockerfile FROM) any Linux distro.

All the containers running on a docker server share the kernel, but otherwise are like little, independent virtual machines.

$ docker run -d  --name mycentos7apache -p 80:80 centos:centos7 bash -c 'yum install -y httpd && apachectl -DFOREGROUND'

$ docker logs -f mycentos7apache &
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message

$ curl --head   # substitute your docker server's ip
HTTP/1.1 403 Forbidden
Date: Sun, 04 Sep 2016 23:06:01 GMT
Server: Apache/2.4.6 (CentOS)

$ docker exec -ti mycentos7apache cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 

Hope that makes sense. Running systemd in your container is problematic at the moment. See and for more info.

1 Like

Hi Jamshid,
You went a bit too low level for me.

OK I understood that.

This maybe the part that is confusing me a bit.

Before going further please understand I’m a “windows guy”.

Can you explain what happens when you run a container from a CentOS image inside an Ubuntu for example? Or is the kernel for most Linux OS distributions the same and what distinguishes them is just the processes and applications installed over the kernel? So when I run a CentOS docker container all its doing is just running the apps processes that make CentOS different from others?


Exactly, a Linux kernel is inside every Linux distro. RedHat/CentOS 7.2 ships with a kernel version 3.10, while Ubuntu 16.04 ships with 4.4, but you can usually upgrade the kernel since it’s backward compatible.

When you run a CentOS7 container on docker it runs that distro but uses the kernel of the docker server.

$ docker run centos:7 uname -a
Linux b3f0a5f004d1 4.4.0-36-generic ...

The binaries available in that container, and the yum package management, are all the same as if you installed CentOS7 on a real machine.

PS: speaking of confusing… I’m not sure what “containers running Windows” means exactly, but it’s coming and sounds interesting:

Thanks Jamshid, very clear now.

I’m definitely staying away from Windows containers for now.

Hi, May be it looks like a duplicate question.

I have my base application in SLES SP3. Now we are thinking to dockerizing the application. The thing is, the base version we are shifting to is RedHat Linux. Could you please clarify below questions :

  1. Does the Docker Engine in RHEL is free ?
  2. If we install Docker Engine in RHEL, Shall we go for my SLES application ported to CentOS and create CentOS image running on RHEL Docker ?
  3. Or we port SLES application to RHEL and create RHEL image itself running on RHEL docker engine?

Which would be more easy and cost effective (The cost is coming considering RHEL is coming under Docker EE). If Docker Engine in RHEL is free of cost, then Option 2 is suits much, right ?

So from the opposite direction : is it possible to run centos 7 docker images on centos 6 host?

A year or two ago, Docker barely ran on CentOS 6 at all. Its Linux kernel is ancient by Docker’s standards, and so you’re dependent on some specific patches being back ported a long long way. I’d really try to upgrade the host, especially if you are trying to use Docker and the application’s runtime environment is isolated from the host’s.

If you can get Docker running, there’s no reason a CentOS 7 based image would work better or worse than any other distro (or no distro at all).

Thanks for the info. Yes unfortunately we stuck on centos 6.8 for the moment.

$ uname -r

$ docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64

I am just curious, if the guest kernel is at 3.10 host is at2.6, will it work? I know the other way around will work because of the backward compatibility.


There is no “guest kernel”; Docker containers use the host’s kernel. The CentOS 6 2.6.32+backports kernel is going to be shaky running Docker at all.

@jamshid : U said that the containerized OS uses the docker server’s kernel. Then how does an ubuntu container run on a windows machine when the docker server (windows) does not even have a linux kernel to support ubuntu?

On Windows or other non Linux OS the docker installer also installs a virtual machine on which the docker engine will be running. That VM has a linux kernel.
The docker engine effectively runs on a virtualized host, not directly on Windows/MacOS.

1 Like

Hi Dmaze, you misunderstood kknd2222.
He wants to know, for Linux host and guests: can the guest’s kernel be an older version than the host?
for instance:
version of host kernel is N;
version of guest is N+1 or N+0.1.
Will that work?

anyone knows the answer, please add your comment!