⚡DevCheats
Cloudflare Edge
đŸŗDevOps â€ĸ Docker & ContainersVerified for Docker Engine 24.0+ & 26.0+âąī¸ 30 secondsđŸŽ¯ Beginner

Docker Restart All Containers Command

Restart all active, stopped, or exited Docker containers in seconds using quiet ID output piping.

Alex Chen
Alex ChenReviewed by Expert

Staff DevOps & Infrastructure Architect

📖3 min read
â€ĸ
📝480 words
â€ĸ
📅Updated 2026-10-30

Verified Command (Single-Click Copy)

Updated: 2026-10-30
bash
docker restart $(docker ps -aq)
Share snippet:𝕏in
âš™ī¸

Interactive Command Customizer

Live Generator

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

Post Host OS Kernel Upgrade:

Quickly restart all background services and database microservices.

Stalled Network or DNS Resolution:

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

Time ComplexityO(N)
Space (Memory)O(1)
Mutates OriginalYes (In-Place)

â„šī¸ Where N is the total number of containers on the host.

✓

Environment & Version Support

Docker CLI
v20.10+Verified
Docker Desktop (Mac/Windows)
v4.0+Verified
Docker Compose v2
v2.20+Verified
Recommended Tool â€ĸ DigitalOcean

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.

bash
docker restart $(docker ps -q)

Using Docker Compose

Restart services defined in your current compose stack without destroying state.

bash
docker compose restart

🔍 People Also Ask (Related Quick Answers)

How to stop all docker containers?docker stop $(docker ps -aq)
How to remove all docker containers?docker rm -f $(docker ps -aq)
How to restart docker daemon service?sudo systemctl restart docker
?

Frequently 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.

đŸ’ŦWas this snippet helpful for your problem?
Next Snippet →

Docker Prune All Unused Resources (Clean Disk Space)

Tags:#docker#containers#restart#devops#cli

More Docker & Containers Snippets

View full Docker & Containers cheatsheet →