by cpuguy83 · 4y ago · 0 comments
Don't generate some random id and a tag (as in the post). Use docker's "-iidfile" flag when building to write the actual id of the image to a file which can then be used in a "docker run".
Likewise, you can use "--cidfile" in a "docker run" to output the id to a file and use that later for accessing it.
docker build --iidfile .dockerid && \
docker run -it /bin/bash --cidfile .dockerid
Without needing to copy and paste the image ID? Is that right? Why wouldn't I just tag the image? docker build -t myimage && \
docker run -it myimage /bin/bash--iidfile writes the image id of the build to a file.
--cidfile writes the container id of the container to a file.
To use the output of --iidfile in a "docker run", instead of specifying an image name call "$(cat <iidfile>)". As an example:
docker build --iidfile out/imageid ...
docker run ... $(cat out/imageid)
--- edit for formatting ---