Golden images are useful when you want to create more containers with same configuration. This also ensure that when you ship an image from Dev to UAT or Prod it will be exactly same as it was when you tested it.
This also avoid problems during release.
So how you create an image from a running container.
Let’s have a look. We have a running container with ID d885f4ea3cff.
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d885f4ea3cff d355ed3537e9 "/bin/bash" 25 hours ago Up 53 minutes ansibleWe already did all the installations in it. So we will commit and create an image “ansible-base” .
docker commit d885f4ea3cff ansible-baseNow if you look at the image list you should see the new image.
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ansible-base latest 1fbdr6f81e4c 39 minutes ago 159 MBYou can create a new container with this image
docker run -t -i -d 1fbdr6f81e4c /bin/bashNotice the “-d” above it will run the container in detached mode so even if you logout of the container it will remain up.
List the containers that are running
docker container lsLogin to the container with container id d985be2f2c3e you created now.
docker exec -it d985be2f2c3e bashIf you want to rename the new container check this post .