How can I get Docker Linux container information from within the container itself? How can I get Docker Linux container information from within the container itself? docker docker

How can I get Docker Linux container information from within the container itself?


Unless overridden, the hostname seems to be the short container id in Docker 1.12

root@d2258e6dec11:/project# cat /etc/hostnamed2258e6dec11

Externally

$ docker ps -aCONTAINER ID        IMAGE               COMMAND             CREATED                 STATUS                      PORTS               NAMESd2258e6dec11        300518d26271        "bash"              5 minutes ago       $ docker -vDocker version 1.12.0, build 8eab29e, experimental


I've found out that the container id can be found in /proc/self/cgroup

So you can get the id with :

cat /proc/self/cgroup | grep -o  -e "docker-.*.scope" | head -n 1 | sed "s/docker-\(.*\).scope/\\1/"


A comment by madeddie looks most elegant to me:

CID=$(basename $(cat /proc/1/cpuset))