Docker Community Forums

Share and learn in the Docker community.

Get a container's full id from inside of itself

docker

(Jfgineste) #1

Hello,

For a project, I absolutely need to know a container’s full id from inside of itself (without executing any command on the host). Is there any way to get this information?

For information, this is the function which I use from the host to get this information, which is obviously unusable from inside of a container.

function docker_full_id(){
  docker inspect $(docker ps | grep "$1" | awk '{print $1}') | grep '"Id":' | awk '{print $2}' | tr --delete '"' | tr --delete ','
}

Many thanks !

Regards


(Jfgineste) #2

Well, it seems that I already found the solution !
I simply have to run the following command from inside a container

cat /proc/self/cgroup | head -1 | tr --delete ‘10:memory:/docker/’

Best regards


(Siju Oommen George) #3

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