How To Stop And Remove All Docker Containers With 2 Simple Commands
In this TechRepublic How to Make Tech Work video, Jack Wallen shows how to stop and remove all Docker containers at once with just two simple commands.
I cannot tell you how many times I’ve had way too many Docker containers running and wanted to just blow them all away and start over. Granted, I wouldn’t do this on a production machine; but if you’re working on a development environment where it doesn’t matter if you kill every running container, then using this nuclear option is a good way to go.
For instance, you might need to deploy a new testing container on a port that some other test container is using. Instead of tracking that container down – and as long as you don’t need any other container to stay running – there’s a much easier solution for this. What I’m about to show you does exactly what it sounds like.
The first command will stop all running containers, and the second command deletes them. It works every time. Here’s how you do it.
To stop all of your running Docker containers, issue the command docker stop $(docker ps -a -q). The next command removes all containers, which is docker remove $(docker ps -a -q).
As you can see, there are two commands: docker remove (or stop) and docker ps -a -q. The first command uses the output of the second command as a variable, so if you have multiple containers running, it’ll either stop or remove them all at once. This command comes in very handy, though remember to use it wisely. If you have any containers running that must remain up, you’re better off stopping and removing the containers manually.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
- The easiest method of installing Docker on Linux (TechRepublic)
- How to fix the Docker Desktop Linux installation with the addition of two files (TechRepublic)
- How to join a node to a Docker Swarm (TechRepublic)
- How to scale Docker Swarm services (TechRepublic)
- Programming languages and developer career resources (TechRepublic on Flipboard)
- Open source
on June 30, 2023, 6:06 PM EDT How to Stop and Remove All Docker Containers with 2 Simple Commands In this TechRepublic How to Make Tech Work video, Jack Wallen shows how to stop and remove all Docker containers at once with just two simple commands. I cannot tell you how many times I’ve had…