Docker restart

svg viewer

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

Format

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.

Format

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

Policies

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.

Examples

unless-stopped:

docker run --restart=unless-stopped edpresso_container

on-failure:

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

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved