Docker: Remove All Images and Containers

By  on  

I've moved to a new project at Mozilla which uses a much different stack than I'm used to; suddenly I'm thrust into a world of Mercurial, Docker, and a few other technologies I'm not accustomed to.  You know what that leads to:  foul language, frustration, booze, and...lots of starting over.  Some hate starting over but wiping the slate clean provides me a bit of ease, knowing that I'm not compounding the problem by trying to patch a fix of a shim.

Starting over in this case means wiping clean my Docker images and containers, just to make sure there are no conflicts or duplicates.  The following commands delete all containers and images:

# Delete every Docker containers
# Must be run first because images are attached to containers
docker rm -f $(docker ps -a -q)

# Delete every Docker image
docker rmi -f $(docker images -q)

Of course you don't want to do this if you're using Docker across multiple projects -- you'll find yourself in a world of hurt if you break your other images and containers.

There you have it -- a clean Docker slate in one pass!

Recent Features

  • By
    Send Text Messages with PHP

    Kids these days, I tell ya.  All they care about is the technology.  The video games.  The bottled water.  Oh, and the texting, always the texting.  Back in my day, all we had was...OK, I had all of these things too.  But I still don't get...

  • By
    CSS 3D Folding Animation

    Google Plus provides loads of inspiration for front-end developers, especially when it comes to the CSS and JavaScript wonders they create. Last year I duplicated their incredible PhotoStack effect with both MooTools and pure CSS; this time I'm going to duplicate...

Incredible Demos

  • By
    Highlighter: A MooTools Search & Highlight Plugin

    Searching within the page is a major browser functionality, but what if we could code a search box in JavaScript that would do the same thing? I set out to do that using MooTools and ended up with a pretty decent solution. The MooTools JavaScript Class The...

  • By
    Create a Dynamic Flickr Image Search with the Dojo Toolkit

    The Dojo Toolkit is a treasure chest of great JavaScript classes.  You can find basic JavaScript functionality classes for AJAX, node manipulation, animations, and the like within Dojo.  You can find elegant, functional UI widgets like DropDown Menus, tabbed interfaces, and form element replacements within...


  1. Raul Leite

    -f to brute force and resolve any conflicts between images and containers:

    docker rmi -f $ (docker images -q)
    docker rm -f $ (ps docker -q -a)
  2. #Stop all dockers

    docker stop $(ps docker -q -a)
  3. Ivan

    Force delete everything with attached volumes:

    docker rm -vf $(docker ps -aq)
  4. There is also new docker command, that will delete all unused images and volumes. It is less brute force and is usually save enough to put in cron on dev machine.

    docker system prune --all

  5. Umesh

    How to remove all docker images in Windows 10?

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!