Restart a Docker container

docker

Updated August 29, 2026

Restart a container with:

docker restart my-container

Docker stops the container, waits for its configured timeout, and starts it again. Set a longer timeout for applications that need graceful shutdown:

docker restart --timeout 30 my-container

For Compose, use docker compose restart service-name. A restart does not rebuild the image, apply a changed environment variable, or recreate the container with new port/volume settings. Use docker compose up -d --force-recreate or an explicit replacement workflow when configuration changed.

If a container repeatedly exits, inspect the reason instead of adding restarts blindly:

docker ps -a
docker logs --tail 100 my-container
docker inspect my-container

A restart policy such as unless-stopped can improve availability for a service, but it can also hide a crash loop. Pair it with health checks and monitoring.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author