Docker Restart All Containers Command
Restart all active, stopped, or exited Docker containers in seconds using quiet ID output piping.
Staff DevOps & Infrastructure Architect
Verified Command (Single-Click Copy)
Updated: 2026-10-30docker restart $(docker ps -aq)Interactive Command Customizer
Toggle flags and arguments below to instantly customize this command for your specific environment:
đ Prerequisites
State Changing / Caution- âDocker Engine 20.10+
- âUser in docker group or sudo privileges
đĄ Primary Use Cases
Quickly restart all background services and database microservices.
Forces Docker bridge network interfaces to re-attach.
# How It Works
The `$(docker ps -aq)` subshell queries Docker for the IDs (`-q` quiet flag) of all containers (`-a` including stopped ones), and passes them directly to `docker restart`.
Expected Terminal Output
f1d9a5b3c2e1
4a8e2b1098cd
c3d4e5f6a7b8
All containers restarted successfully.Gotcha & Common Pitfall
If you only want to restart currently running containers (avoiding booting up stopped test containers), omit the `-a` flag: `docker restart $(docker ps -q)`.
Performance & Complexity
âšī¸ Where N is the total number of containers on the host.
Environment & Version Support
Deploy Docker Containers in 30s
Get $200 free credit to host Docker apps, databases, and microservices on high-performance cloud VMs.
# Alternative Methods & Variations
Restart running containers only
Excludes stopped and exited containers.
docker restart $(docker ps -q)Using Docker Compose
Restart services defined in your current compose stack without destroying state.
docker compose restartđ People Also Ask (Related Quick Answers)
docker stop $(docker ps -aq)docker rm -f $(docker ps -aq)sudo systemctl restart dockerFrequently Asked Questions about Docker Restart All Containers Command
How do I restart only running containers without restarting stopped ones?âŧ
Run "docker restart $(docker ps -q)" without the "-a" flag. The "-a" flag lists all containers including exited ones.
What is the difference between docker stop + start vs docker restart?âŧ
docker restart sends a SIGTERM signal, waits for a grace period (default 10 seconds), and then sends SIGKILL before instantly booting the container back up.
How do I change the restart timeout?âŧ
Use the -t flag: "docker restart -t 30 $(docker ps -aq)" to wait 30 seconds before forcing a kill.