How to clear in Docker?

PHPz
Release: 2023-04-25 09:33:25
Original
4257 people have browsed it

Docker is an open source application container engine that allows developers to easily create and deploy applications and run them in any environment. One of the benefits of Docker containerized applications is that they run within independent containers, isolated from the host system and avoiding conflicts. However, the number of Docker containers created may be large, and it is easy to produce some unused or abandoned containers. The status of these containers may be "", resulting in redundant container images and need to be cleared in time.

In this article, we will introduce how to clear the status in a Docker container.

  1. View containers

Before performing the cleanup operation, we need to first determine which containers are marked as "". We can view it with the following command:

docker ps -a | grep "<none>"
Copy after login

The output may look like this:

862746adc245        ubuntu:latest       "/bin/bash"         5 days ago          Up 5 days                               one-missing-container
9ac7da8db12f        centos:7            "/bin/bash"         5 days ago          Exited (0) 5 days ago                                              lucid_curie
99e099c008a0        centos:7            "/bin/bash"         5 days ago          Exited (0) 5 days ago                                              youthful_elion
Copy after login

In the above output, the first column is the ID of the container, and the second column is the image name of the container. , the third column represents the command of the container, the fourth column represents the creation time of the container, the fifth column represents the running status of the container, and the sixth column represents the name of the container.

It can be seen from the above results that the status of three containers is "".

  1. Clear containers

Clearing containers with status is very simple, just use the following command:

docker rm $(docker ps -aq --filter "status=dead" --filter "status=exited" --filter "status=created")
Copy after login

The above command The following actions will be performed:

  • Select stopped, exited, and created containers from the container list.
  • Use the -docker RM command to delete these containers.

Please note that if you only want to remove specific stopped containers, you can use docker ps -a | grep "Exited" command to find the IDs of all stopped containers and use docker rm command Delete them.

  1. Clearimages

Once the container is deleted, we can continue to clean up the abandoned images, which may no longer be used, but are used in In some cases, it cannot be deleted. Use the following command to clear abandoned images:

docker rmi $(docker images -f "dangling=true" -q)
Copy after login

The above command will select all tagged images from the list and delete them.

  1. Use less Docker's

Finally, it is recommended that you avoid the status in Docker containers and images. It is recommended that you explicitly name and label your containers or images when you create them. This can help you better manage Docker images and containers and avoid unnecessary mental burden.

Summary

This article introduces how to clear the status in Docker containers and images. The number of Docker containers may be large, and the status needs to be cleared in time to avoid redundancy and unnecessary occupation. With these simple steps, you can easily manage your Docker environment and become more efficient.

The above is the detailed content of How to clear in Docker?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!