Skip to content

Instantly share code, notes, and snippets.

@anokun7
Last active September 10, 2015 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anokun7/9474a051937cdd712bdf to your computer and use it in GitHub Desktop.
Save anokun7/9474a051937cdd712bdf to your computer and use it in GitHub Desktop.
To remove all docker images or containers directly from commandline
# Need to force
# Ideally run this after removing the containers so that the images are not being used
for i in $(docker images | tail -n +2 | awk '{ print $3 }'); do docker rmi -f $i ; done
# Need to stop the container before removing it
# Instead of 'docker stop', you can also run 'docker kill'.
for i in $(docker ps -a | tail -n +2 | awk '{ print $1 }'); do docker stop $i && docker rm $i ; done
@anokun7
Copy link
Author

anokun7 commented Aug 18, 2015

Need to force

Ideally run this after removing the containers so that the images are not being used

for i in $(docker images -q); do docker rmi -f $i ; done

Need to stop the container before removing it

Instead of 'docker stop', you can also run 'docker kill'.

for i in $(docker ps -aq); do docker stop $i && docker rm $i ; done

@anokun7
Copy link
Author

anokun7 commented Aug 18, 2015

for i in $(docker ps -aq); do docker stop $i && docker rm $i ; done && for i in $(docker images -q); do docker rmi -f $i ; done

@anokun7
Copy link
Author

anokun7 commented Sep 10, 2015

Much quicker / nifitier

docker rm -f $(docker ps -qa) && docker rmi -f $(docker images -q)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment