Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Docker»How to Remove Docker Images and Containers

    How to Remove Docker Images and Containers

    RahulBy RahulMarch 1, 20162 Mins ReadUpdated: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)
    
    Docker Docker Containers Docker Images
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Docker on CentOS 7 & RHEL 7
    Next Article How to Export and Import Docker Containers

    Related Posts

    How to Install Docker Compose on Ubuntu 20.04

    4 Mins Read

    Docker-compose for MySQL with phpMyAdmin

    2 Mins Read

    Docker-compose with Persistent MySQL Data

    3 Mins Read

    How to Install Docker on Ubuntu 20.04

    Updated:June 2, 20213 Mins Read

    How to Add a Comments in Dockerfile

    1 Min Read

    How to Install Docker on CentOS/RHEL 8

    Updated:June 21, 20203 Mins Read

    9 Comments

    1. Anil on January 3, 2020 6:33 am

      Thanks Rahul.

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

      Thank you bro .. this work :v

      Reply
    3. docker on January 22, 2019 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?

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

      dhanyawaad Rahul!

      Reply
    5. Sagar on February 22, 2018 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?

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

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

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

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

      Reply
    8. Albert Barkley on April 7, 2017 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.

      Reply
    9. san on February 5, 2017 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.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.