A Zsh utility that provides a convenient command to terminate all running Docker containers with enhanced reporting and container ID tracking. Works great on Pop OS and other Linux distributions.
- Kill all running Docker containers with a single command
- Option to gracefully stop containers instead of force killing
- Display container IDs and names before operations
- Detailed success/failure reporting for each container
- Built-in confirmation prompt to prevent accidental termination
- Zsh command completion integration
- Error handling for Docker daemon connectivity issues
- Zsh shell (can be installed via
sudo apt install zsh) - Docker installed and running
- Terminal access
# Clone the repository
git clone https://github.com/[your-username]/docker-kill-all.git
# Run the installation script
cd docker-kill-all
chmod +x add_docker_kill_all.sh
./add_docker_kill_all.sh
# Activate the function in your current session
source ~/.zshrcIf you prefer to install manually, you can add the function directly to your ~/.zshrc file:
- Copy the
docker-kill-allfunction to your~/.zshrc file - Activate the function
source ~/.zshrc
To remove the function from your Zsh, manually remove the function from ~/.zshrc
docker-kill-all
docker-kill-all -f
docker-kill-all -s
docker-kill-all -h
Found 3 running containers:
- abc123def456 (nginx-proxy)
- fed987cba654 (mysql-db)
- 123abc456def (redis-cache)
This will kill ALL running Docker containers listed above.
Are you sure you want to continue? (y/n) y
Killing all containers...
Results:
Successfully terminated containers:
✓ abc123def456 (nginx-proxy)
✓ fed987cba654 (mysql-db)
✓ 123abc456def (redis-cache)
All containers have been terminated successfully.The script adds a function to your Zsh configuration that:
- Retrieves a list of all running Docker containers
- Displays their IDs and names
- Asks for confirmation (unless forced with -f)
- Terminates each container using either
docker killordocker stop - Reports on the success or failure of each operation
Command not found: Make sure you've sourced your.zshrcfile after installationDocker daemon not running: Ensure Docker is running withsystemctl status dockerPermission denied: You may need to add your user to the docker group with:sudo usermod -aG docker $USERThen log out and back in
If you see Error: Cannot connect to Docker daemon, try:
- Check if Docker is running:
systemctl status docker - Start Docker if it's not running:
sudo systemctl start docker
- Tested on: Pop OS 22.04, Ubuntu 20.04, Debian 11
- Requires: Zsh 5.0+ and Docker 19.03+
- Version: 1.0.0
Warning: This tool will terminate ALL running Docker containers. Use with caution in production environments. It's primarily designed for development and testing environments.
MIT License
Copyright (c) 2025 PKramek
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Contributions are welcome! Feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request