Joined August 2013
·

Evgeny Chernyavskiy

Senior Software Engineer at Alexander Street Press
·
Washington D.C. Metro Area
·
·

Posted to Docker Cheat Sheet with examples over 1 year ago

There are at least two more options to conveniently retain a Docker container ID:

# Assign to a shell variable.
DOCKER_CID=$(docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done")
# Specify a CID file.
docker run -d -cidfile /tmp/my_container.cid ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"
# then elsewhere one could just
cat /tmp/my_container.cid

In my opinion the second option is particularly useful when one uses named containers - a CID file could always be named after the container name and easily referenced that way.

Achievements
11 Karma
0 Total ProTip Views