Which OS is running in my Docker container?

Solution 1:

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

Solution 2:

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.