Skip to content

Instantly share code, notes, and snippets.

@nmarley
Created December 8, 2016 13:58
Show Gist options
  • Save nmarley/0ee3e2cf14dabfb868eb818b8b30e7e0 to your computer and use it in GitHub Desktop.
Save nmarley/0ee3e2cf14dabfb868eb818b8b30e7e0 to your computer and use it in GitHub Desktop.
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
@radekl
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
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