Home > Blockchain >  Why does 'docker stop CONTAINERID' also removes my stopped container?
Why does 'docker stop CONTAINERID' also removes my stopped container?

Time:09-25

If I run docker stop CONTAINERID, docker also deletes my stopped container, so I cannot restart it afterwards. Is there a way to avoid that?

As a note, I ran the container doing docker run --rm -dit --name somename someimages:v1.2.3 and Docker version is 20.10.

CodePudding user response:

From the docker documentation for run you can read:

By default a container’s file system persists even after the container exits. This makes debugging a lot easier (since you can inspect the final state) and you retain all your data by default. But if you are running short-term foreground processes, these container file systems can really pile up. If instead you’d like Docker to automatically clean up the container and remove the file system when the container exits, you can add the --rm flag:

So run the container without --rm

CodePudding user response:

Remove --rm from your docker run command because of --rm argument docker is removing your container when you stop your container.

Correct Docker run command -

docker run -dit --name somename someimages:v1.2.3
  • Related