Docker – Why Does a CentOS Docker Container Identify as Ubuntu

dockerkernelprocversion

I am trying to verify When choosing a Docker container image file for my Ubuntu, what do I need to match between them?

On Lubuntu, a CentOS container says it is CentOS, by

$ sudo docker run centos bash -c "cat /etc/*-release "
CentOS Linux release 7.6.1810 (Core) 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.6.1810 (Core) 
CentOS Linux release 7.6.1810 (Core) 

but also says it is the same Ubuntu as the host:

$ sudo docker run centos bash -c "cat /proc/version"
Linux version 4.15.0-46-generic (buildd@lgw01-amd64-038) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019


$ cat /proc/version
Linux version 4.15.0-46-generic (buildd@lgw01-amd64-038) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019
  1. I wonder why the two commands differ in OS distribution and kernel version?

  2. Does a container share the same kernel as its host? If yes, should their kernel versions be the same? When choosing a Docker container image file for my Ubuntu, what do I need to match between them? says "you don't need to match distributions or kernel versions."

Best Answer

cat /proc/version is showing kernel version. As containers run on the same kernel as the host. It is the same kernel as the host.

cat /etc/*-release is showing the distribution release. It is the OS version, minus the kernel.

A container is not virtualisation, in is an isolation system that runs directly on the Linux kernel. It uses the kernel name-spaces, and cgroups. Name-spaces allow separate networks, process ids, mount points, users, hostname, Inter-process-communication. cgroups allows limiting resources.

Related Question