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
Charity
Fork and commit to someone's open source project in need
There are at least two more options to conveniently retain a Docker container ID:
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.