Docker is growing in popularity enough to be the near-perfect application creation and hosting tool. With Docker, you don't need to worry about compatibility and environment. In this Docker tutorial, we'll show you some of the basics: how to delete containers, images, and more!
Docker Tutorial: delete Images in Docker
Remember, before using Docker, you need to install it on VPS. You can access the server with PuTTY! If you have problems, please review tutorial ours!
Docker: Xóa Images
Apply option -a to view one or more images with Image ID of each image in the system.
From this list, select the ID of the image you need to remove, then use the command rmi, as shown in the example below.
You can select multiple images by selecting Image IDs. The following commands will help to remove one or more specific or different files:
Command to view the list:
$ docker images –a
Command to delete images:
$ docker image rmi <image_id>
Command to delete multiple images:
$ docker images rmi <image_id> <image_id>
Docker: Xóa Dangling Images
Dangling images are images that are not related to the tagged image. Usually these images are unused and just take up disk space. We can find these images using the filter -f with string dangling=true. These images can be deleted at a later time.
To view dangling images, use the command below:
$ docker images –f dangling=true
To remove or remove dangling images, use:
$ docker images purge
Docker: Remove image theo mẫu
Removing certain images in our opinion is easy and fast in Docker. We have to run specific commands inside the terminal to see a list of multiple images that match the pattern.
Then we will use the command awk with Image ID to delete specific image.
If we want to remove the image according to a specific pattern, we can do it in just a few commands! First, we will need to use Docker together command grep to list the images, then delete them with the command awk.
To specify the template in the terminal, use:
$ docker images –a | grep "pattern"
To delete an image, use:
$ docker images –a | grep "<ImageId>" | awk '{<Print $1>}' | xargs docker rm
Hướng dẫn docker: Remove Container
To remove containers in Docker, you must follow the same steps as when removing images. First, use option -a to list containers, then use the command rm to delete one or more containers:
To view containers, use:
$ docker container -a
To remove a container, use the command below:
$ docker container rm <container ID>
To delete multiple containers, type:
$ docker container rm <container ID> <container ID>
Docker: Delete Container on application exit
If you don't need the container after creating it, then you can simply use the command -rm to delete it.
$ docker run –-rm <container_name>
Docker: Remove Container theo mẫu
To see all containers that match your pattern, use the command below. The process is roughly similar to what you would use to delete an image by pattern:
$ docker ps -a | grep "pattern”
Next, just use the rep command with awk to remove the container:
$ docker ps -a | grep "pattern" | awk '{print $1}' | xargs docker rmi
Docker: Remove Volumes
Use command ls to see the list of volumes and check the volume names of the ones you want to remove. Then use command rm as in the example:
List volume:
$ docker volume ls
Delete one or more volumes:
$ docker volume rm <volume_name> <volume_name>
Docker: Remove Dangling Volumes
Volumes do not exist without containers. If you remove containers and leave volumes blank, they will not be automatically removed. To delete volumes, we can follow the same process as deleting dangling images:
First, we can list all dangling volumes using the filter -f, then use the prune command to remove dangling volumes.
List dangling volumes:
$ docker volume ls –f dangling=true
Remove dangling volumes:
$ docker volume prune
Docker: Remove container and its volume
Unnamed volumes can be deleted with their containers using the option -v:
$ docker rm -v <container_name>
Summary
Docker allows you to work in chaotic environments. But after using Docker for a longer time, you may have leftover images, volumes, and containers taking up valuable disk space. In this tutorial, we have shown you some basics of Docker: remove containers, images, volumes by different technique.
We hope this Docker tutorial helps you keep your workflow neat! See you in the next part!
Post a Comment
Post a Comment