How to Restart a Docker Container the Right Way

Summarize this article with:
Your container is stuck. The application stopped responding ten minutes ago.
Knowing how to restart a Docker container quickly gets your services back online without losing configuration data or mounted volumes.
Whether you’re running a single Nginx instance or managing multiple containers through Docker Compose, the restart process takes seconds once you know the right commands.
This guide covers five methods to restart containers using the Docker CLI, including timeout configuration, batch operations, and the stop-start alternative.
You’ll also learn how to verify successful restarts and troubleshoot common issues like containers stuck in restarting loops or permission errors.
How to Restart a Docker Container

Restarting a Docker container is the process of stopping a running container and starting it again using the Docker CLI or Docker Compose.
Users need to restart containers when applications become unresponsive, after configuration changes, to clear memory leaks, or to apply environment variable updates.
This guide covers 5 methods requiring under 2 minutes each, suitable for beginners with basic command line experience.
Prerequisites
Before you restart a Docker container, verify these requirements.
Required Software
- Docker Engine 20.10 or later installed
- Docker Desktop (Windows/macOS) or Docker CE (Linux)
- Docker Compose v2.0+ for multi-container environments
System Requirements
- Linux, macOS 10.15+, or Windows 10/11 with WSL2
- Terminal or PowerShell access
- User added to docker group (Linux) or administrator privileges
Time and Skill Level
Each method takes 30 seconds to 2 minutes.
Basic familiarity with command line operations is sufficient.
Step One: How Do You Restart a Container Using the Docker Restart Command?
The docker restart command stops a running container gracefully and starts it again with the same configuration, volumes, network settings, and environment variables intact.
Run the command from any terminal window where Docker is accessible.
The container returns to running state within seconds.
Action
Open your terminal and run:
“ docker restart containername `
Or use the container ID:
` docker restart 3a7d8f2e1b4c `
Expected output: The container name or ID echoes back, confirming the restart completed.
Purpose
This command handles the stop-start sequence automatically.
It sends SIGTERM to allow graceful shutdown, waits for the timeout period, then starts the container with preserved state.
Step Two: How Do You Find Your Container Name or ID?
Every Docker container has a unique 64-character ID and an assigned name, both visible through the docker ps command, which you need to target specific containers for restart operations.
Action
List all containers (running and stopped):
` docker ps -a `
Output columns you need:
- CONTAINER ID: First 12 characters of the unique identifier
- IMAGE: The Docker image the container runs
- STATUS: Current state (Up, Exited, Restarting)
- NAMES: Human-readable container name
For running containers only:
` docker ps `
Copy either the ID or NAME value for your restart command.
Purpose
Accurate identification prevents restarting the wrong container.
The short ID (first 12 characters) works the same as the full 64-character version.
Step Three: How Do You Restart a Container Using Docker Compose?
Docker Compose restarts services defined in your docker-compose.yml file, handling container dependencies and network configurations automatically for multi-container applications.
Action
Navigate to the directory containing your docker-compose.yml:
` cd /path/to/your/project `
Restart a specific service:
` docker compose restart servicename `
Restart all services in the compose file:
` docker compose restart `
The command only restarts containers; it does not rebuild images or recreate containers.
Purpose
Use this method when managing applications with multiple linked containers like web servers, databases, and cache services.
It maintains the container orchestration defined in your compose configuration.
Step Four: How Do You Restart a Container with a Specific Timeout?
The -t flag sets a custom grace period in seconds before Docker sends SIGKILL, giving applications more time for graceful shutdown operations like closing database connections or saving state.
Action
Restart with a 30-second timeout:
` docker restart -t 30 containername `
Default timeout is 10 seconds.
Signal sequence: Docker sends SIGTERM first, waits for the timeout period, then sends SIGKILL if the process hasn’t stopped.
Purpose
Database containers (PostgreSQL, Redis, MySQL) and applications with cleanup routines need longer timeouts to prevent data corruption.
Step Five: How Do You Restart All Running Containers at Once?
Command substitution passes all running container IDs to the restart command, executing a batch restart operation useful after Docker daemon updates or host system changes.
Action
Restart all running containers:
` docker restart $(docker ps -q) `
Restart all containers including stopped ones:
` docker restart $(docker ps -aq) `
Filter by image name before restarting:
` docker restart $(docker ps -q --filter ancestor=nginx) `
Purpose
Batch operations save time when managing multiple containers in production environments or after applying system-wide configuration changes.
Alternative Method: Stop and Start Sequence
Running docker stop followed by docker start achieves the same result as restart but provides more control between operations.
Comparison
| Method | Execution | Signal Handling | Best For |
docker restart | Atomic; one command initiates the cycle. | Sends SIGTERM, waits 10s, then SIGKILL. | Quick resets, automated scripts, and CI/CD pipelines. |
docker stop + start | Manual; two distinct operations. | Full grace period control; allows mid-process checks. | Debugging, configuration auditing, and logs inspection. |
When to Choose Each
Use docker restart for routine operations and CI/CD pipelines.
Use stop-start when you need to inspect container logs or verify state between operations.
Verification
Confirm the restart succeeded by checking container status and uptime.
Check Container Status
` docker ps --filter name=containername `
Look for STATUS column showing “Up X seconds” with recent timestamp.
View Container Logs
` docker logs --tail 50 containername `
Recent startup messages confirm the application initialized correctly after restart.
Verify Application Response
For web containers, test the endpoint:
` curl http://localhost:port/health `
Troubleshooting
Container Fails to Restart
Issue: Container exits immediately after restart.
Check exit codes:
` docker inspect containername --format='{{.State.ExitCode}}' `
Common codes: 0 (success), 1 (application error), 137 (killed by SIGKILL), 143 (killed by SIGTERM).
View error logs:
` docker logs containername `
Container Stuck in Restarting Loop
Issue: Status shows “Restarting” repeatedly.
Check the restart policy:
` docker inspect containername --format='{{.HostConfig.RestartPolicy.Name}}' `
Disable automatic restart temporarily:
` docker update --restart=no containername `
Permission Denied Errors
Issue: Cannot connect to Docker daemon.
Add user to docker group (Linux):
` sudo usermod -aG docker $USER `
Log out and back in for changes to take effect.
Application Not Responding After Restart
Issue: Container runs but application is unresponsive.
Verify port bindings:
` docker port containername `
Check if the process is running inside:
` docker exec containername ps aux `
Related Processes
Continue building your DevOps container management skills with these guides:
- How to create a Docker container
- How to check if Docker is running
- How to SSH into Docker container
- How to exit Docker container
- How to remove Docker images
- What is a Docker image
- Where are Docker volumes stored
- Kubernetes vs Docker
FAQ on How To Restart A Docker Container
How do I restart a Docker container?
Run docker restart containername in your terminal.
This command sends SIGTERM to stop the container gracefully, waits 10 seconds, then starts it again with the same configuration, volumes, and network settings preserved.
What is the difference between docker restart and docker stop/start?
The docker restart command combines stop and start into a single operation.
Using separate commands lets you inspect container logs or check status between operations, which helps during debugging or troubleshooting unresponsive applications.
How do I restart all Docker containers at once?
Use command substitution: docker restart $(docker ps -q) for running containers.
Add the -a flag like docker restart $(docker ps -aq) to include stopped containers in the batch restart operation.
Why does my Docker container keep restarting?
A restart policy set to “always” or “unless-stopped” triggers automatic restarts.
Check with docker inspect containername –format='{{.HostConfig.RestartPolicy.Name}}’ and review exit codes in container logs for application errors.
How do I restart a Docker container with Docker Compose?
Navigate to your project directory containing docker-compose.yml and run docker compose restart servicename.
This restarts the specified service while maintaining network connections and dependencies defined in your configuration management file.
What happens to data when I restart a Docker container?
Data in Docker volumes and bind mounts persists through restarts.
Data stored only in the container’s writable layer also survives restarts but will be lost if the container is removed, so always use volumes for persistent storage.
How do I set a restart policy for a Docker container?
Use the –restart flag when creating containers: docker run –restart=unless-stopped imagename.
Options include “no”, “on-failure”, “always”, and “unless-stopped” for controlling automatic restart behavior after crashes or Docker daemon restarts.
Can I restart a stopped Docker container?
Yes. The docker restart command works on both running and stopped containers.
For stopped containers, it simply starts them using the existing container configuration without needing to specify the original run parameters again.
How long does it take to restart a Docker container?
Default timeout is 10 seconds for graceful shutdown, plus application startup time.
Customize with docker restart -t 30 containername for applications needing longer shutdown periods like databases closing connections properly.
How do I restart Docker daemon without stopping containers?
Enable live restore in Docker’s daemon.json: {“live-restore”: true}.
This keeps containers running during Docker Engine restarts or upgrades, preventing downtime in high availability environments where service continuity is critical.
Conclusion
Understanding how to restart a Docker container keeps your applications running smoothly and minimizes downtime during container troubleshooting.
The Docker restart command handles most scenarios in seconds, while timeout flags give database containers like PostgreSQL and Redis the grace period they need.
Batch operations using command substitution scale your container management across entire environments.
Docker Compose restart works best for multi-service applications with defined dependencies.
Always verify restarts by checking container status and reviewing logs for startup errors.
Set appropriate restart policies during container creation to automate failure recovery without manual intervention.
These methods work across Linux, macOS, and Windows with WSL2, giving you consistent container lifecycle control regardless of your Docker host platform.
- Android App Drawer vs Home Screen: Differences Explained - April 16, 2026
- 7 Things to Know Before Buying Refurbished Servers in 2026 - April 16, 2026
- iPhone Parental Controls: Complete Guide - April 15, 2026







