How can I keep ALL changes made to a docker container?

159 views Asked by At

I'm using docker as a "light" virtual machine. For example, when I need to do some experiments on Ubuntu and don't want to mess up the host OS, I simply run docker run -it ubuntu bash.

Generally I'm very happy with it, except that I cannot keep the changes after I exit, which means I need to rerun

apt update && apt install vim git python python3 <other_tools> && pip install flask coverage <other_libraries> && .....

every single time I start the docker container as a VM, which is very inefficient.

I've noticed this question, but it only enables me to keep some specific files from being erased, whereas I want the whole system (including but not limited to all configuration, cache and tools installed) to be retained between the life cycles of the docker container.

1

There are 1 answers

1
user2915097 On

You must use something like

docker commit mycontainer_id myuser/myimage:12

see the doc: docker commit

and then you launch your saved image myuser/myimage:12

But you should definitely use a Dockerfile