Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have to delete docker containers?

What artifacts do stopped docker containers leave on the host file system that makes it necessary to run the command "docker container prune". I thought docker containers where simply running versions of images that are suppose to be wiped out after they exit? In what scenarios are artifacts left behind if it is not always the case?

like image 773
user2561417 Avatar asked Oct 17 '19 01:10

user2561417


People also ask

What does deleting a docker container do?

Remove a container and its volumes This command removes the container and any volumes associated with it. Note that if a volume was specified with a name, it will not be removed.

Why after stopping a container you need to remove it?

Its always better to stop the container and then remove it using the remove command. Stopping the container and then removing it will allow sending SIG_HUP signal to recipients. This will ensure that all the containers have enough time to clean up their tasks.

Why is docker killing my container?

The container has consumed too much memory, and has been killed by the host OS: If the operating system detects that it's running out of memory, it might start killing processes to free up memory. If a container is using a lot of memory or resources, it might be killed by the OS.


Video Answer


1 Answers

If you don't use --rm to auto-remove the container when it exits then the container is only stopped, not removed. It can be resumed with docker start. You can run new commands inside it with docker exec. All of the files that were modified during the container's runtime are still there: log files, data files, anything that was modified, added, or removed. Docker also keeps around metadata like the container's logs and its exit status in case you want to do a post mortem inspection.

It should be standard practice to use --rm so containers clean up after themselves. Otherwise you'll have to periodically clean up your system.

like image 189
John Kugelman Avatar answered Sep 30 '22 21:09

John Kugelman