• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Remove Docker Images and Containers

Written by Rahul, Updated on January 24, 2019

In our previous tutorials you have learned about installation of Docker engine on CentOS/RHEL and Ubuntu operating system and pulled images from Docker hub. After that created containers with images. This tutorial will help you to remove unnecessary Docker images and containers from your host machine.

  • How to Export and Import Docker Containers

Remove Docker Images

To remove an images, Docker provides rmi option. Using this we can delete any docker images from our local system. For example use below command with changing <IMAGE ID> with your Docker image id.

docker rmi <IMAGE ID>

To list all available docker images on your system use the following command. This will help you to find the ID of images.

docker images

REPOSITORY     TAG        IMAGE ID            CREATED          VIRTUAL SIZE
centos         latest     2933d50b9f77        11 days ago      196.6 MB
ubuntu         latest     36248ae4a9ac        11 days ago      188 MB

Remove Docker Containers

To remove a containers, Docker provides rm option. Using this we can delete any docker containers from our local system. For example use below command with changing <CONTAINER ID> with your Docker container id.

docker rm <CONTAINER ID>

To list all containers on your system using ps option, but ps will show only running containers. So to view all containers use -a parameter with ps.

docker ps -a

CONTAINER ID   IMAGE    COMMAND      CREATED       STATUS      PORTS  NAMES
f2582758af13   ubuntu   "/bin/bash"  2 hours ago   Up 2 hours         first_ubuntu
2b199b9976c4   centos   "/bin/bash"  3 days ago    Up 3 hours         thirsty_yalow

Stop & Remove All Docker Containers

To remove all docker containers from your system use the following commands. The first command will stop all running Docker containers and then the second command will delete all docker containers from your system.

Stop All Containers

docker stop $(docker ps -a -q)

Remove All Containers

docker rm $(docker ps -a -q)

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

9 Comments

  1. Avatar Anil Reply
    January 3, 2020 at 6:33 am

    Thanks Rahul.

  2. Avatar achmad rivaldi Reply
    May 20, 2019 at 5:44 am

    Thank you bro .. this work :v

  3. Avatar docker Reply
    January 22, 2019 at 11:52 am

    Awesome Article and helpful to fix my Docker container force remove, can you also let me know who to remove attached volume?

  4. Avatar Srikanth Reply
    June 29, 2018 at 8:01 am

    dhanyawaad Rahul!

  5. Avatar Sagar Reply
    February 22, 2018 at 8:40 am

    What should be the deletion cycle?
    container 1st, then images 2nd and volume 3rd? Or something else you would like to suggest?

  6. Avatar live streams Reply
    September 25, 2017 at 1:39 pm

    That was points of fact! In this article you hold an exciting instructive information and utilized for my exploration.

  7. Avatar Have A Look Reply
    August 30, 2017 at 12:13 pm

    Excellent article. Exceptionally fascinating to read. I truly love to read such a pleasant article. Thanks! keep rocking.

  8. Avatar Albert Barkley Reply
    April 7, 2017 at 10:37 am

    Thank you very much for sharing lines of code that will help me to get best things. I will try this code myself to see the results.

  9. Avatar san Reply
    February 5, 2017 at 8:42 am

    if we create a docker with a name following steps mentioned by you still leaves instance, and if you try to create a container of an image with the same name you will get error. that container already exists even if you have stopped and removed the container.

Leave a Reply Cancel reply

Popular Posts

  • How to View or List Cron Jobs in Linux
  • How to Install PHP 8 on Ubuntu 20.04
  • How to Set Up SSH Tunnel with PuTTY
  • How to Install Tor Browser on Ubuntu 20.04
  • Issue with phpMyAdmin and PHP: Warning in ./libraries/sql.lib.php#613 count(): Parameter must be an array or an object that implements Countable”
  • How to Allow Remote Connections to MySQL
  • How to Install MySQL 8.0 on Ubuntu 20.04
  • How to Install Apache Kafka on Ubuntu 20.04
© 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy