Check Linux Distributions

I encounter a problem that check which OS is running in my docker container, or extend it as how to check which OS am I using?

1
2
3
4
5
6
7
cat /etc/os-release

NAME="Red Hat Enterprise Linux Server"
VERSION="7.5 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
...
1
2
3
4
5
6
7
8
9
10
11
12
hostnamectl

Static hostname: example.com
Icon name: computer-vm
Chassis: vm
Machine ID: e57cfe9136e9430587366e04f14195e1
Boot ID: 6ebe05de8b7f43c0bfa36d2c62b702de
Virtualization: kvm
Operating System: Red Hat Enterprise Linux Server 7.5 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.5:GA:server
Kernel: Linux 3.10.0-862.14.4.el7.x86_64
Architecture: x86-64

For docker image, you can use docker image inspect command:

1
2
3
4
5
6
docker image inspect <image name>:<tag> | grep -i "base image"

"org.label-schema.schema-version": "= 1.0
org.label-schema.name=CentOS Base Image
org.label-schema.vendor=CentOS
...
0%