docker container 命令小技巧

批量停止

  1. $ docker container ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. cd3a825fedeb nginx "/docker-entrypoint.…" 7 seconds ago Up 6 seconds 80/tcp mystifying_leakey
  4. 269494fe89fa nginx "/docker-entrypoint.…" 9 seconds ago Up 8 seconds 80/tcp funny_gauss
  5. 34b68af9deef nginx "/docker-entrypoint.…" 12 seconds ago Up 10 seconds 80/tcp interesting_mahavira
  6. 7513949674fc nginx "/docker-entrypoint.…" 13 seconds ago Up 12 seconds 80/tcp kind_nobel

方法1

  1. $ docker container stop cd3 269 34b 751

方法2

  1. $ docker container stop $(docker container ps -aq)
  2. cd3a825fedeb
  3. 269494fe89fa
  4. 34b68af9deef
  5. 7513949674fc
  6. $ docker container ps -a
  7. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  8. cd3a825fedeb nginx "/docker-entrypoint.…" 30 seconds ago Exited (0) 2 seconds ago mystifying_leakey
  9. 269494fe89fa nginx "/docker-entrypoint.…" 32 seconds ago Exited (0) 2 seconds ago funny_gauss
  10. 34b68af9deef nginx "/docker-entrypoint.…" 35 seconds ago Exited (0) 2 seconds ago interesting_mahavira
  11. 7513949674fc nginx "/docker-entrypoint.…" 36 seconds ago Exited (0) 2 seconds ago kind_nobel
  12. $

批量删除

和批量停止类似,可以使用 docker container rm $(docker container ps -aq)

Note

docker system prune -a -f 可以快速对系统进行清理,删除停止的容器,不用的image,等等