Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Tim Salva
Tim Salva

Posted on • Edited on • Originally published atblog.jtsalva.dev

     

How to remove all docker containers in a network

Update
Thanks@hasnayeen for making me aware of the following better approach

docker <stop|rm> $(docker ps -qf "network=<NAME>")
Enter fullscreen modeExit fullscreen mode

Steps

How to list docker containers in a network

Inspecting a docker network will list containers along with other information, we can use the--format flag to get a newline separated list.

docker network inspect <NAME> --format='{{range $id, $_ := .Containers}}{{println $id}}{{end}}// Example output197123ceff4c60ad99518e948047d842eab52ab7eac38476dabe22ac5f6cc2092ec40124c66a394d6f29e1448bff3182902a94e74f923c7cab4f10c3d7f99d1daeb2b9d5686efcf186adf13ce6b8471782f332385aa8b2c4314932a1416f8376
Enter fullscreen modeExit fullscreen mode

Stopping and removing containers in a docker network

docker <stop|rm> $(docker network inspect <NAME> \    --format='{{range $id, $_ := .Containers}}{{println $id}}{{end}}')
Enter fullscreen modeExit fullscreen mode

After much Googling I couldn't find how to do this anywhere, if there's a better way please let me know.

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
hasnayeen profile image
Nehal Hasnayeen
Frantically typing on the keyboard hoping something will eventually work
  • Location
    Bogura, Bangladesh
  • Joined

you can use this command to remove all containers in a network

docker rm $(docker ps -q -f "network=<NAME>")
Enter fullscreen modeExit fullscreen mode
CollapseExpand
 
jtsalva profile image
Tim Salva
  • Location
    United Kingdom
  • Work
    Software Engineer
  • Joined

Thanks@hasnayeen, time for me to switch to using this.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    United Kingdom
  • Work
    Software Engineer
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp