docker-clean - remove unused containers and images
-E or --no-exited Do not remove exited containers.
-D or --no-dangling Do not remove dangling images.
-c or --created Remove created containers.
--running Remove running containers.
--all Remove all containers except running. ie. exited, dangling, and created.
-h or --help Print usage.
Create a container which does not remove itself
$ docker run --detach ubuntu:latest
96f6ac01abd856046e12367fd17e6b62a2251a26015625e5ec4c5fadc1b85b2f
Container has stopped and it is not removed
$ docker ps --all --filter "status=exited"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96f6ac01abd8 ubuntu:latest "/bin/bash" 15 seconds ago Exited (0) 14 seconds ago nostalgic_noether
Remove it using docker-clean(1)
$ docker-clean
96f6ac01abd8
Create a dangling image
$ cat <<EOF | docker build .
FROM ubuntu:latest
RUN uname
EOF
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM ubuntu:latest
---> f49eec89601e
Step 2 : RUN uname
---> Using cache
---> 3190681e7fc0
Successfully built 3190681e7fc0
Image is dangled
$ docker images --filter "dangling=true"
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 3190681e7fc0 1 minutes ago 129.5 MB
Remove it using docker-clean(1)
$ docker-clean
Deleted: sha256:3190681e7fc0c7e0587390dc5024445b737467245b3cc3b5e9203a05171f295b
Create a container
$ docker create ubuntu:latest
2a1ae9172833d5097bd5f7fba45aab79a533eca721eb9213f154196936449432
Container is created
$ docker ps --all --filter "status=created"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a1ae9172833 ubuntu:latest "/bin/bash" 10 seconds ago Created backstabbing_bassi
Remove it using *docker-clean(1) and its --created option
$ docker-clean --created
2a1ae9172833
Report bugs at https://github.com/gportay/docker-scripts/issues
Copyright (c) 2017 Gaël PORTAY
This program is free software: you can redistribute it and/or modify it under the terms of the MIT License.