single command to stop and remove docker container

前端 未结 11 1140
失恋的感觉
失恋的感觉 2021-01-30 15:17

Is there any command which can combine the docker stop and docker rm command together ? Each time I want to delete a running container, I need to execu

相关标签:
11条回答
  • 2021-01-30 15:47

    In my case, to remove the running containers I used

     docker rm -f $(docker ps -a -q) 
    

    In case you also need to remove the images, then run docker rmi $(docker images -q) afterwards.

    Only run docker rmi $(docker images -q) if you want to remove the images.

    0 讨论(0)
  • For removing a single container

    docker rm -f CONTAINER_ID
    

    For removing all containers

    docker rm -f `docker container ps -qa`
    
    0 讨论(0)
  • 2021-01-30 15:49

    To remove all stopped containers docker system prune

    To stop live container, docker stop CONTAINER_ID waits 10 sec and it calls docker kill CONTAINER_ID

    Or with docker kill CONTAINER_ID, you can immediately stop the container

    0 讨论(0)
  • 2021-01-30 15:50

    https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/

    You can use kill, and also by using rm and the force flag it will also use kill.

    0 讨论(0)
  • 2021-01-30 15:52

    Remove all containers: docker ps -aq | xargs docker rm -f

    0 讨论(0)
  • 2021-01-30 15:58

    You can use :

    docker rm -f CONTAINER_ID
    

    It will remove the container even if it is still running.

    https://docs.docker.com/engine/reference/commandline/rm/

    You can also run your containers with --rm option, it will be automatically removed when stopped.

    https://docs.docker.com/engine/reference/run/#clean-up-rm

    Edit: The rm -f might be dangerous for your data and is best suited for test or development containers. @Bernard's comment on this subject is worth reading.

    0 讨论(0)
提交回复
热议问题