How to check if running inside Docker?

To check if you are inside a docker container, run the command

If you get some result with docker in it, you are inside a docker container.


identify docker container

See Docker

Need help with Linux Server or WordPress? We can help!

One thought on “How to check if running inside Docker?

  • This doesn’t work with cgroup 2.0, and it doesn’t work inside Docker Desktop on Mac.

    [email protected]:/# cat /proc/self/cgroup

    The presence of a /.dockerenv file on the root filesystem in Linux is probably a more reliable way to know that you’re running inside a Docker container, but that doesn’t give you your container Id; it’s just an empty file.

    There needs to be a less fragile way to 1) detect when you’re running in a container, and 2) get your own container Id. The Docker team really dropped the ball on this. At a minimum, they should have put the container Id inside /.dockerenv.

Leave a Reply

Your email address will not be published. Required fields are marked *