Showing posts with label create image from docker container. Show all posts
Showing posts with label create image from docker container. Show all posts

Solved: How to create an image of a docker container.

So you have completed all the installation on a docker container and now you want to keep it as golden image.
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 ansible
We already did all the installations in it.  So we will commit and create an image “ansible-base” .
docker commit d885f4ea3cff ansible-base
Now 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 MB
You can create a new container with this image
docker run -t -i -d 1fbdr6f81e4c /bin/bash
Notice 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 ls
Login to the container with container id d985be2f2c3e you created now.
 docker exec -it d985be2f2c3e bash
If you want to rename the new container check this post .