Stopping Docker containers by image name - Ubuntu

后端 未结 16 1222
故里飘歌
故里飘歌 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:53

    Two ways to stop running a container:

    1. $docker stop container_ID
    
    2. $docker kill container_ID
    

    You can get running containers using the following command:

    $docker ps
    

    Following links for more information:

    • https://docs.docker.com/engine/reference/commandline/stop/
    • https://docs.docker.com/v1.8/reference/commandline/kill/
    0 讨论(0)
  • 2020-12-12 10:53

    For Docker version 18.09.0 I found that format flag won't be needed

    docker rm $(docker stop $(docker ps -a -q -f ancestor=<image-name>))
    
    0 讨论(0)
  • 2020-12-12 10:54

    I was trying to wrap my Docker commands in gulp tasks and realised that you can do the following:

    docker stop container-name
    docker rm container-name
    

    This might not work for scenarios where you have multiple containers with the same name (if that's possible), but for my use case it was perfect.

    0 讨论(0)
  • 2020-12-12 10:56

    You could start the container setting a container name:

    docker run -d --name <container-name> <image-name>
    

    The same image could be used to spin up multiple containers, so this is a good way to start a container. Then you could use this container-name to stop, attach... the container:

    docker exec -it <container-name> bash
    docker stop <container-name>
    docker rm <container-name>
    
    0 讨论(0)
提交回复
热议问题