The docker rm CONTAINER_ID command can be used to remove a single powered off container. For example the below command will remove a docker container with a container ID ae559727f76c:
# docker rm ae559727f76c
ae559727f76c
To remove all docker containers we first need to get all container ID's currently found on our docker host. To do this a docker command docker ps -aq can be used:
# docker ps -aq
4c3acdf2b4cb
3818e42ced85
a27bb0c7982d
5be2fdaeb65e
dae5632d8b35
Since the above command only outputs the actual containers ID's we can use it as so called command substitution to the original docker rm CONTAINER_ID. The following linux command will removed all currently not running docker containers on your docker host system:
# docker rm `docker ps -qa`
Error response from daemon: Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f
3818e42ced85
a27bb0c7982d
5be2fdaeb65e
dae5632d8b35
FATA[0003] Error: failed to remove one or more containers
The above error message means that one or more of your containers are still running where all others have been successfully removed. If you are sure that you want to remove also any currently running docker containers add --force flag to your docker remove command. The following linux command will delete all containers regardless of their current status.
# docker rm --force `docker ps -qa`
4c3acdf2b4cb
FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: