63

Most of the time, using one of these two, I can tell which OS is running in my Docker container (alpine, centOS, etc)

But this time, I can't tell:

bash-4.2$ uname -a       
Linux 6fe5c6d1451c 2.6.32-504.23.4.el6.x86_64 #1 SMP Tue Jun 9 20:57:37 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

bash-4.2$ more /etc/issue
\S
Kernel \r on an \m

Any way to get a text version of the OS it is running ?

Bob Yoplait
  • 741
  • 1
  • 5
  • 6

5 Answers5

89

I like to use Screenfetch. You might want to try that.

If you look into the code you can see how it determines the distribution:

  • lsb_release -sirc
  • cat /etc/os-release

And to cover CentOS too:

  • cat /etc/issue
0 _
  • 103
  • 5
Janosch Gräf
  • 1,046
  • 8
  • 7
  • 3
    "/etc/os-release" is indeed a good source, but is not present on some centOS. If you have only one shot to decide, I would say: "ls /etc/*release". But if one need the string way, you need both "cat /etc/os-release" and "cat /etc/issue" to cover all cases. Thank you both of you. – Bob Yoplait Sep 26 '16 at 21:02
  • 2
    Yeah on alpine they both work `cat /etc/issue` and `cat /etc/alpine-release`! – Julian Nov 15 '19 at 15:10
9

uname will tell you the kernel that's running, which is the host OS kernel (containers, unlike VM's, share the same kernel).

To identify the base image of the container, there's no guaranteed solution from inside the container. You can look for pointers from the major vendors like Janosch gives (/etc/os-release for most vendors like Debian, CentOS and Alpine, or /etc/lsb-release for Ubuntu). You can also check the package management tools if they are installed (/etc/apk, /etc/apt, /etc/yum).

Outside of the container, you can inspect the image and track down the layers to see where the image comes from, but that gets into locating sha256 checksums. The best method is to review the Dockerfile that was used the build the image.

BMitch
  • 5,189
  • 1
  • 21
  • 30
  • When I run this on windows with the latest Ubuntu image, as of today, `uname` just returns `Linux`, and `uname -a` just returns `Linux 89e9cd67fc7a 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux` – David Culbreth Mar 01 '19 at 03:23
  • 1
    Linuxkit is the embedded Docker VM, which is the host OS with containers run on Docker for Windows. – BMitch Mar 01 '19 at 10:21
  • 1
    "uname" will give you details about the underlying host, not the container (even if you run it inside a container). – Trondh Oct 11 '19 at 09:58
  • 1
    @Trondh I believe that's what I said. Is there something in the answer that needs to be corrected? – BMitch Oct 11 '19 at 10:42
  • I tried running `uname` inside my container and got `Linux` (it's an Alpine-based image, from what I understand), but my host is a Mac, and running it outside the container returns `Darwin`. Based on this answer I'd expect them to be the same, so don't know if that's a misinterpretation, or something odd about the containers/images I'm using, or something that's changed in Docker in the intervening years. – Max Starkenburg Sep 07 '22 at 23:27
  • There are no native runtimes for Mac. Docker Desktop runs a Linux VM on Mac and Windows, and that VM runs the containers. – BMitch Sep 07 '22 at 23:53
5

On a docker trimmed container, this worked for me after no luck with /etc/release, /etc/issue, lsb_release, etc. (I know some are for specific Distros):

Execute this command as root:

# cat /proc/version
Linux version 4.19.121-linuxkit (root@18b3f92ade35) (gcc version 9.2.0 (Alpine 9.2.0)) #1 SMP Thu Jan 21 15:36:34 UTC 2021

SOURCE: https://unix.stackexchange.com/questions/23833/how-can-i-tell-what-version-of-linux-im-using/326917#326917

Patricio
  • 155
  • 1
  • 5
0

This works for me, but one has to be outside of a container :

docker exec container-name cat /etc/os-release

When you execute the same command from the bash prompt of the inside of a container, it gives the host system characteristics.

That's probably due to the fact that once it is launched the docker container shares most of the system resources to stay lightweight. I'm under Linux though, Windows users may have a different result.

Joel.O
  • 419
  • 4
  • 8
0

In docker container, there should be a file named debian_version under etc folder. You can do cat debain_version. It will show you the debian version.