Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Docker — get container ID from within Docker container
bash-4.3# cat /proc/1/cpuset
/docker/13f8c221656e202db979d1e607c9c902282d8719ab70715978dd04ee6069d61e
bash-4.3# DOCKER_CID=$(cat /proc/1/cpuset | cut -c9-)
bash-4.3# echo $DOCKER_CID
13f8c221656e202db979d1e607c9c902282d8719ab70715978dd04ee6069d61e
@nmarley

This comment has been minimized.

Copy link
Owner Author

nmarley commented Dec 8, 2016

Or:

cut -c9- < /proc/1/cpuset
@radekl

This comment has been minimized.

Copy link

radekl commented Jan 11, 2018

After most recent update of docker (on MacOS) it may be better to use:

awk -F/ '{ print $NF }' /proc/1/cpuset

$ cat /proc/1/cpuset
/docker-ce/docker/dfffffff5ac7468ef6117c44274bde16185fd9330f96561b1fffffffb16e05f8
@soloecho

This comment has been minimized.

Copy link

soloecho commented May 8, 2018

Thanks, it helps a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.