Score:3

What linux name and version will I see in a container?

ky flag

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?

Score:4
in flag

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)"
..
Score:-1
cn flag

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.

co flag
That is not how the layered filesystem works. At no time does it expose the filesystem of the host unless you have mounted a volume.
Prem avatar
cn flag
You are not contradicting what I said. I have not indicated mounting or not , @BMitch , I have only said that what you see inside may or may not be what you see outside ! What Exactly is wrong there ? Maybe you are mixing my Answer with the other Answer ?
co flag
" When `/etc/os-release` is not updated in Container , it will give Details of Host." that is incorrect. If the file does not exist in the container, there will be no file. `docker run --rm busybox cat /etc/os-release` will show "no such file or directory", and will not show the value from the host.
Quantim avatar
in flag
This is not correct, the `/etc/os-release` never gives details of host Container file system is not layered on top of the host filesystem, but on the base image defined by `FROM` in `Dockerfile`
Prem avatar
cn flag
I wanted to avoid complicating the Explanation & confusing OP , hence I avoided mentioning mounting , which I have now included , @BMitch , Do have a look !
Prem avatar
cn flag
When Host `/etc/` is mounted at Container `/etc/` ( for what-ever reason or configuration ) , then Container will see Host `/etc/os-release` , @Quantim , until that file is "updated" in Container.
co flag
This answer is still very confusing and misleading. It doesn't cover the case where the container does not have a `/etc/os-release` and the original answer implied the layered filesystem would fall back to the host values. This answer now implies that it will always contain some content and half the time that content will be from the host (where that's a very rare exception scenario).
Prem avatar
cn flag
My Answer will not cover the Case where `/etc/os-release` is missing , because OP is not asking about that : OP wants to know why the `/etc/os-release` is either matching Host or not matching Host , @BMitch , I gave the reasons (earlier without mentioning Mount Points & now with Mount Points) including the Crux **"The Container root `/` file system is not the Same as the Host root `/` file system"** from which everything follows **almost automatically** : Container `/etc/` is not Same as Host `/etc/` : Technically , there is nothing wrong in My Answer.
co flag
"Debian Docker Host running Ubuntu Docker Container , without own `/etc/os-release` : `/etc/os-release` will contain Debian." can you provide a `docker run` command, without a volume mount, showing that this is correct?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.