Home » Development and Build » Development Environment Setup » How to save / commit changes to docker image ?

How to save / commit changes to docker image ?

This post is in continuation with our previous post, “How to run Ubuntu 18.04 in docker container ?” , as mentioned in previous post, suppose you get to console and does some work like creating files, installing some packages etc, and “exit” from that shell and after some time you again started the same Ubuntu image, you will see all the work you done previously has been lost, and you have to start all over again.

We will first show if you didn’t saved, how you end up loosing the data.. and then will show how you can save the data in container..

Check which are the docker images installed on your system,

Here, we will use only Ubuntu 18.04 image, hence login to the same container as,

Now, lets go to home directory and create some temporary files as,

Now, lets check on another console,

We can see that the Ubuntu image is running.. now lets exit from the Ubuntu container console using exit command,

Now, we will be back on our host machines console.. now lets login again and see if our previous work is still there or not..

as you can now see, “ls” command returned empty.. but actually we had created “helloworld.txt” file in our container as seen above.. so we can see that all our data is lost .. so what to do ???

How to save / commit the data in container ?

The answer to our problem above is that, we need to manually save or commit the data you worked on in container so as once you login again, your all things like packages installed, code or files gets preserved in your django container..

Now, lets say we have created “helloworld.txt” in our container, and then before exiting from the container

here, our working docker image container ID is “375e83b53588” , so we need to save the data using “CONTAINER ID” as,

So, now the data will be saved and we will see a new image got created as,

As you can see above, new docker image with “IMAGE ID” “a4a181159e32” got created.. so if you login to this new image as,

you will see your data is commited..


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment