Find out If you are Running Inside a Container

How to Find out If you are Running Inside a Container ?

In this article I will show you how to know if you are running inside a container like Dockers or not.

What is Systemd ?

To understand or find out if you are running inside a container we will start by understanding a main concept first, Systemd is the main Init which manages all the process and everything after boot.

/proc/

Proc folder is where you can get a lot of information about your system and processes.

Now how to find if i am in a container ?

Let us trace and inquiry the Systemd running process:

cat /proc/1/cgroup/

If you are getting an output with root folder like "/" then it's a VM or physical machine, if it shows /docker or /lxc ...etc then you are inside a container.

 

How to know that you are using a Physical or Virtual Machine ?

Now what after knowing that it's not a container but still want to dig deep.

There are several commands which can tell you if you are running a Virtual or Physical machine.

1- virt-what

virt-what

2- Dmidecode

This is one of my favorite commands which you can pull a lot of information about the box using it, one of it's benefits that you can query the system like below:

dmidecode -s system-product-name

3- Query the disk

ls /dev/disk/by-id "if you get results it means it's physical"

4- Check the message log

 dmesg | grep -i virtual


Subscribe to
for video tutorials updates