Stopping Docker containers by image name - Ubuntu

后端 未结 16 1432
故里飘歌
故里飘歌 2020-12-12 10:04

On Ubuntu 14.04 (Trusty Tahr) I\'m looking for a way to stop a running container and the only information I have is the image name that was used in the Docker run comma

16条回答
  •  旧巷少年郎
    2020-12-12 10:47

    Adding on top of @VonC superb answer, here is a ZSH function that you can add into your .zshrc file:

    dockstop() {
      docker rm $(docker stop $(docker ps -a -q --filter ancestor="$1" --format="{{.ID}}"))
    }
    

    Then in your command line, simply do dockstop myImageName and it will stop and remove all containers that were started from an image called myImageName.

提交回复
热议问题