Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert a Docker container back to its original image without restarting it?

Normally, people are all about making Docker persist data in their containers and there are about twenty million questions on how to do exactly that, but I'm a tester and I want to dump all that crap I just did to my data and revert to my known state (aka my image).

I'm aware I can do this by spinning up a new container based on my image but this forces me to disconnect and reconnect any network connections to my container and that's a huge pain.

Is it possible to revert a running container to its original image without restarting it?

like image 790
user2859458 Avatar asked Nov 30 '25 00:11

user2859458


2 Answers

Sadly while it's running you won't be able to revert or change the image. You'll need to stop your running containers and remove them. Once your volumes are no longer attached to any containers, running the command docker volume prune will destroy all volumes not currently attached to containers.

Then you can simply restart your docker containers from the images, and you'll have a fresh start again.

I also found this article to be a great reference when I was learning docker: https://web.archive.org/web/20190528002402/https://medium.com/the-code-review/top-10-docker-commands-you-cant-live-without-54fb6377f481

like image 148
Nebri Avatar answered Dec 02 '25 15:12

Nebri


To revert back to the original state, you have to restart the container - this is important because a container image is just a bunch of files, the actual running container must start some process and because of that, you cannot revert the container while running, since that process will most likely have issues.

So to answer your question - restart the container, a docker image only takes milliseconds to start up - the rest of the time is the process starting up.

like image 43
Michael Avatar answered Dec 02 '25 14:12

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!