Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

docker command

Docker restart

Educative Answers Team
svg viewer

Docker has an extremely straightforward syntax to restart one or more containers.


docker restart {Options} {Container Name}
Name, Shorthand Description
- -all, -a Show all containers
- -quiet, -q Only display numeric IDs

To check which containers are active and running, use docker ps. Then, either restart a single container or restart all containers.

Restarting a single container

docker restart edpresso_container

Restarting all containers

docker restart $(docker ps -a -q)

Restart policy

Docker also lets the user set the restart policy upon exit or failure. Users can type docker ps to check if the restart policy is active; it will be shown as either Up, when the container is up and running, or Restarting when the container is in the restart state.


docker run --restart={Policy} {Container Name}


Policy Result
no Do not automatically restart the container when it exits. This is the default.
on-failure[:max-retries] Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.
always Always restart the container regardless of the exit status.
unless-stopped Always restart the container regardless of the exit status, including on daemon startup, except if the container was put into a stopped state before the Docker daemon was stopped.



docker run --restart=unless-stopped edpresso_container


docker run --restart=on-failure:15 edpresso_container

Note: When restarting, an increasing delay is added after each restart. This delay starts from 100ms and doubles at every restart until the on-failure limit is reached or the docker container is stopped explicitly. This is done to avoid overflooding the server.

For analytics purposes, the user can inspect how many times the container has restarted:

docker inspect -f "{{ .RestartCount }}" edpresso_container

Or the last time the container restarted:

docker inspect -f "{{ .State.StartedAt }}" edpresso_container


docker command
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring