Showing posts with label docker-container. Show all posts
Showing posts with label docker-container. Show all posts

Wednesday, November 13, 2024

How to remove docker containers and images

In this tutorial, we are going to learn how to remove the docker containers and images

Initially, list all the containers that use the docker images. To see all the running containers on your machine use the following command

docker ps -a

This will show all the running containers on your machine. The sample output looks like as below:

Here, we do have one running container with container ID: 767c0a92e087 and container name: oracle19.3c

Stop a running container

docker stop <container_id>

Use your own container ID in our case it is 767c0a92e087 to stop it

Now, let's delete the container

docker rm <container_id>

To force to remove the running container in one command use the following command

docker rm -f <container_id>

If you want to remove all the containers(not recommended)

docker container prune

Let's look into deleting the docker images

List all the available docker images

docker image ls

The sample output looks like

elint@elint:~$ docker image ls
REPOSITORY        TAG         IMAGE ID       CREATED       SIZE
oracle/database   19.3.0-ee   dd6c130762a3   11 days ago   6.54GB

To delete the specific image

docker rmi <image_id>

Use your own docker image ID in our case it is dd6c130762a3

To remove the docker image forcefully

docker rmi -f <image_id>

To remove unused images. The unused or dangling images are those images which are not associated with docker images

docker image prune

Note: the deleted images need to re-download if we need it later

These are the overall commands to clean up the docker containers and images.

Share: