3

I execute cat /etc/os-release in a container.

I have an Ubuntu 22.04 docker host. When I run a container, and see the linux os-release file inside the container, I see my Ubuntu name, regardless in which container I execute it...

However I also have an other Kubernetes cluster also on Ubuntu 22.04 (no docker, the cluster configured to use containerd directly). If I create a deployment based on any image, when I see the os-release file, I see an image specific linux name, which clearly comes from the image itself, sometime alpine, sometime bookworm, etc.

Why is this different behavior?

2 Answers2

4

The /etc/os-release file is based on the container base image, if you get same version as your host, it only means you run images based on Ubuntu 22.04 You can test it with the container based on different system

Example from my machine running on Ubuntu, first command from host, second from container

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.2 LTS"
...
$ docker run --rm -ti node:16 bash
root@3d48cdfe1d97:/# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
..
Quantim
  • 1,396
  • 10
  • 15
-1

DETAILS :

Docker Containers have a layered file system.
The Container root / file system is not the Same as the Host root / file system.
The Container /etc/ is not the Same as the Host /etc/ !

In that Scenario , Container /etc/os-release may or may not be Host /etc/os-release !
[[ Depends on what is mounted where ]]

With the layering , if the Container is still using the Host /etc/os-release file [[ because of the Mount Points & Mappings ]] , then we will see the Host OS Details , whereas if the Container is using own or modified /etc/os-release file , then we will see the Contents of that file which may be Same or Different.

Debian Docker Host running Ubuntu Docker Container , without own /etc/os-release : /etc/os-release will contain Debian.

Debian Docker Host running Debian Docker Container , with own /etc/os-release : /etc/os-release will contain Debian.

Debian Docker Host running Ubuntu Docker Container , with own /etc/os-release : /etc/os-release will contain Ubuntu.

SUMMARY :

When /etc/os-release is updated in Container [[ It has own /etc ]] , then it will give Details of Container.
When /etc/os-release is not updated in Container [[ Original /etc/ is made available via Mounting to Same Mount Point /etc/ ]] , then it will give Details of Host.

Prem
  • 598