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?
Cancel --rm option on running docker container
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]
Disclaimer:
In the production environment, you should never change the container by running bash
or sh
in it. Use Dockerfile
and docker build
instead. Dockerfile
will give you a reproducible configuration even you delete your container. By design, the container should not have any important data (aka not persistent). Use the image and volumes to save your custom changes and configurations.