Categories

Category cover

Automation
43 posts

Category cover

Security
20 posts

Category cover

Notes
19 posts

Category cover

Personal Security
15 posts

Category cover

CISO
14 posts

Category cover

Infrastructure
12 posts

Category cover

Learning paths
9 posts

Category cover

OT/ICS
6 posts

Category cover

UNetLab
4 posts

Category cover

Books
3 posts

Category cover

Write-up
3 posts

Category cover

OSInt
2 posts

Category cover

My life
1 posts

Clean a Docker host

Andrea Dainese
August 11, 2021
Post cover

The following scripts allow cleaning a Docker host, and stopping and deleting containers and images.

Stop all containers:

#!/bin/bash

CONTAINERS=$(docker ps -a | tail -n+2 | cut -d" " -f1)
if [ "$CONTAINERS" == "" ]; then
        exit
fi
docker stop $CONTAINERS

Stop and delete all containers:

#!/bin/bash

CONTAINERS=$(docker ps -a | tail -n+2 | cut -d" " -f1)
if [ "$CONTAINERS" == "" ]; then
        exit
fi
docker stop $CONTAINERS
docker rm $CONTAINERS

Delete all unused images:

#!/bin/bash

IMAGES=$(docker images | awk '{ print $3 }'| tail -n+2)
if [ "$IMAGES" == "" ]; then
        exit
fi
docker rmi $IMAGES &> /dev/null