Docker刪除大量停止的container


1. 怎么做

官方建議的批量刪除停止容器使用docker rm $(sudo docker ps -a -q)

千萬不要用 docker rm -f $(sudo docker ps -a -q),會刪除全部容器的

2. 為什么這么做

1. docker ps -a -q

docker ps 命令的解釋:

docker ps -a -q 列出所有容器的數字ID

root@haha:~# docker ps --help

Usage:  docker ps [OPTIONS]

List containers

Options:
  -a, --all Show all containers (default shows just running) -f, --filter value Filter output based on conditions provided (default []) --format string Pretty-print containers using a Go template --help Print usage -n, --last int Show n last created containers (includes all states) (default -1) -l, --latest Show the latest created container (includes all states) --no-trunc Don't truncate output -q, --quiet Only display numeric IDs -s, --size Display total file sizes

具體看看,docker ps 是列出容器的命令

  • -a 列出所有的容器
  • -q 只顯示數字ID 

2. docker rm命令的解釋:

root@haha:~# docker rm --help

Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove one or more containers

Options:
  -f, --force Force the removal of a running container (uses SIGKILL) --help Print usage -l, --link Remove the specified link -v, --volumes Remove the volumes associated with the container
  • -f 強制刪除,可以刪除正在運行的容器

  • -v 容器啟動后,數據會以volumes的形式存在於硬盤中,即使刪除了container數據也不會刪除,加上這個參數那么容器執行的數據也會被刪除 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM