i'm trying to start up tomcat on my docker desktop,and i followed the official tomcat tutorial on docker hub.but somehow i found that docker will create a new container everytime after running the command:docker run -it --rm tomcat and delete the container automatically when tomcat shuts down.
i have already known the reason is that run --rm can automatically remove the container when it exits.
now i finally built webs on tomcat,and i don't want them to be vanished. how can i save my container before it's deleted?
thx! ;D
CodePudding user response:
Based on what I've found on the internet, remove the --rm
flag is not possible currently. docker update
gives you the ability to update some parameters after you start your container, but you cannot update the cleanup flag (--rm
) according to the document.
References:
I started a docker container with --rm Is there an easy way to keep it, without redoing everything?
But some workaround can be applied. You can export your current container to an image, act as a checkpoint, then you can start a new container without the --rm
flag, and based on the image you exported. You can use docker commit
to do so:
docker commit [your container name/id] [repo/name:tag]
(Use docker ps
to list your containers, do it in a new bash/cmd/PowerShell session, or you will lose your work when you exit your docker container)
Then start a new container without the --rm
flag:
docker run -it [repo/name:tag]