Jump to content

How to free up space when using docker containers?


FunkyBuddha

Recommended Posts

Posted

I recently had a free space crisis. A docker application was consuming so much space that it started triggering alarms and notifications. The first thing I did was to stop container. Remove and delete the containers and images and found the disk space was not released. What the heck is going on?

Apparently, I forgot to issue this command:

  • docker system prune (this will remove all stopped containers, unused images and  network address and free up the space for the OS).

 

Normally this command runs pretty quick, but in my case, it ran for over 12 hours due to the amount of space it has consumed. I was SSH'd into my server and was worried that if my connection disconnected, the command would abnormally terminate. Well, I did get disconnected, but the process continued to run in the background. After completing, it automatically rebooted the server and I got my free space back. I hope this helps the next person that encounters this problem.

  • Thanks 1
  • SuperModerator
Posted

This is a great topic, helping those having the same problem.

I rated it 5 ★★★★★ :ty:

Posted

An updated script to clean your docker instance.

Bash script:

Quote

vacuum_docker() {
    sudo docker system df

    # for a detailed view
    sudo docker system df -v

    read -p "DOCKER CLEANUP: Make sure to START ALL containers! Please hit ENTER to confirm or CTRL-C to cancel!"

    sudo docker container prune -f
    sudo docker image prune -f
    sudo docker network prune -f
    sudo docker volume prune -f
    sudo docker system prune -a -f

#    Uncomment to remove all unused (ie. not running) containers
#    sudo docker rm -v $(sudo docker ps -a -q -f status=exited)
#    sudo docker rmi -f  $(sudo docker images -f "dangling=true" -q)
#    sudo docker volume ls -qf dangling=true | xargs -r docker volume rm

#    Uncomment to WIPE ALL docker data
#    systemctl stop docker
#    rm -rf /var/lib/docker
#    systemctl start docker
}

 

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...