I'm trying to learn the ins and outs of Docker, and I'm confused by the prospect of saving an image.
I ran the basic Ubuntu image, installed Anaconda Python and a few other things...so now what's the best way to save my progress? Save, commit, export?
None of these seem to work the same way as VirtualBox, which presents an obvious save-state file for your virtual machine.
That's why its ideal to have to changes in docker file and in short, there is no save state feature in docker system like we have in virtual machines. The memory contents are always lost.
Hence, if you want the changes to persist, you can use the Docker commit command. The commit command will save any changes you make to the container and create a new image layer on top of it.
Dockerfile Command to Keep the Container Running Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.
The usual way is at least through a docker commit
: that will freeze the state of your container into a new image.
Note: As commented by anchovylegend, this is not the best practice, and using a Dockerfile allows you to formally modeling the image content and ensure you can rebuild/reproduce its initial state.
You can then list that image locally with docker images
, and run it again.
Example:
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours focused_hamilton $ docker commit c3f279d17e0a svendowideit/testimage:version3 f5283438590d $ docker images REPOSITORY TAG ID CREATED SIZE svendowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
After that, if you have deployed a registry server, you can push your image to said server.
The usual way is at least through a docker commit: that will freeze the state of your container into a new image.
But know that there is no reliable way to "save state" of container unlike virtual machine save state in Hyper-V or VMware. This is a downside also to docker.
It seems it only saves the changes made to the persistent file changes. So when you spin up the container again from new images, the dependencies and all the run commands executed will not have same effect.
That's why its ideal to have to changes in docker file and in short, there is no save state feature in docker system like we have in virtual machines. The memory contents are always lost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With