How to determine if a process runs inside lxc/Docker?

后端 未结 16 1360
情歌与酒
情歌与酒 2020-11-28 18:15

Is there any way to determine if a process (script) runs inside an lxc container (~ Docker runtime)? I know that some programs are able to detect whether they run inside a v

16条回答
  •  感情败类
    2020-11-28 19:07

    Docker creates a .dockerenv file at the root of the directory tree inside container. You can run this script to verify

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


    MORE: Ubuntu actually has a bash script: /bin/running-in-container and it actually can return the type of container it has been invoked in. Might be helpful. Don't know about other major distros though.

提交回复
热议问题