Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to bulk import or delete image and container scripts by Docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how Docker batch imports or deletes image and container scripts". In daily operation, I believe many people have doubts about how Docker batch imports or deletes image and container scripts. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how Docker batch imports or deletes image and container scripts". Next, please follow the editor to study!

After using Docker for a period of time, there will be many useless images locally, and it takes time to manually delete them one by one, so get a script to delete them in batches, as follows: delete the name of the image starting with 192.168.33.10. As long as the image is not used, it will be deleted.

List-1

Docker images | awk'{print $1 ":" $2}'| grep 192.168.33.10 | xargs-t docker rmi

If the following is true, containers that are not running except mysql, postgresql, kibana, elastic, and mongo will be deleted, and the-t parameter of xargs will print out the executed command.

List-2

Docker ps-a | egrep-v 'mysql | post | kiban | elas | mongo' | awk' {print $1}'| xargs-t docker rm

Sometimes there are some images, such as List-3, which may be generated temporarily. It is not possible to delete such images and use those in List-1 directly.

List-3

Mjduan@mjduan:/opt/tmp/images$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE fb522ae76d1c 3 days ago 993MB 4966b6e23631 3 days ago 662MB 3d30ff829e3d 3 days ago 738MB 82d66f605ccd 3 days ago 738MB 53df78f6d849 3 days ago 683MB Dd914a092541 3 days ago 738MB

List-4

# in this case, note that the awk should be separated by\ t so that the following awk can get the desired $2docker images | awk'{print $1 "\ t" $3}'| grep "

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report