/proc/1/cgroups does not tell if I am inside of contianer

In aim to check if we are inside of container we need to type (it is taken from the web):

# docker container exec -it ub bash
root@8d6a3b7407c5:/# cat /proc/1/cgroup

‘ub’ is the name of Ubuntu Docker image.

Before I created container like that:

# docker container run -itd --name ub ubuntu:latest bash

As you can see inside of my container there is no any ‘docker’ word after the /. Why?

When I do it on my macOS using Docker Desktop I get the same result, but Docker Desktop uses cgroup v2 in the virtual machine and I have cgroup v1 on my Linux where I can see more.

I don’t know what is the best way to check that if you are in a container, since it could be other contaier not created by Docker, but in case of Docker, you could for example check the mountinfo

cat /proc/1/mountinfo

Or the mount command would be easier to use in a script:

mount | grep 'overlay on /'

If it returns something, it is probably a container:

overlay on / type overlay (rw,relatime,lowerdir=/var/lib/docker/overlay2/l/2VXBE3ETYFJ6U26GXDORMTSYEE:/var/lib/docker/overlay2/l/35BQNRRKIP7OZQDT7KLUCAQOJD,upperdir=/var/lib/docker/overlay2/3a009df8e82ff8d25b10527111283ea3bd90471ccf5fab00626e53bd468d4ae1/diff,workdir=/var/lib/docker/overlay2/3a009df8e82ff8d25b10527111283ea3bd90471ccf5fab00626e53bd468d4ae1/work)

On the other hand, systemd uses an environment variable to work differently in a container.

Thanks for hint.

I also check in this way, but not sure if it makes sense.
When I type on Host I see:

# df -h
Filesystem                                                                                                 Size  Used Avail Use% Mounted on

The same command in the contianer:

root@8d6a3b7407c5:/# df -h
Filesystem                                                                                                                                                                                                        Size  Used Avail Use% Mounted on
fuse-overlayfs                                                                                                                                                                                                    523G   27G  496G   6% /

I mean, I see only /