Reasons for cleaning in Docker

One of the valuable and significant reasons we’ll enjoy Docker is when the environment we provisioned for it has lots of space. However, sometimes even with enough space made available, we still experience space issues. To curb this issue, we realize there’s a need to clean up our Docker environment often. Most times, what occupies the provisioned space isn’t our application running but other items not useful in the environment. Once the Docker environment gets filled up, applications won’t work any longer.

Resources that occupy space

Here are the items that might be occupying space in an environment:

  • Exited containers: These are containers no longer running or useful in our environment. They have exited while performing what they were provisioned for but are still lying fallow in the Docker environment.

  • Exited images: These are images that were in a container in the Docker environment but exited because the container wasn’t running anymore. These images are still found within the Docker environment, taking up space. Docker images that aren’t in running containers are called dangling images.

  • Unused volumes: Volumes that aren’t in use by any container but are still in the Docker environment.

  • Log files: When running lots of containers, we might run into a scenario of the logs taking disk space and reducing the speed and delivery of our application.

  • Unused networks: These are networks that aren’t in use any longer.

Cleaning container resources

Removing stopped containers:

To get a list of containers that are no longer running, we use the following command:

Get hands-on with 1400+ tech skills courses.