How to check if a process is running inside docker container

后端 未结 8 1273
逝去的感伤
逝去的感伤 2020-11-30 23:08

[Updated1] I have a shell which will change TCP kernel parameters in some functions, but now I need to make this shell run in Docker container, that means, the shell need to

8条回答
  •  星月不相逢
    2020-11-30 23:33

    Docker creates .dockerenv and .dockerinit (removed in v1.11) files at the top of the container's directory tree so you might want to check if those exist.

    Something like this should work.

    #!/bin/bash
    if [ -f /.dockerenv ]; then
        echo "I'm inside matrix ;(";
    else
        echo "I'm living in real world!";
    fi
    

提交回复
热议问题