The landscape of app deployment and administration has been radically transformed by the rise of container technology, in which Docker stands as a quintessential model. A cornerstone of managing containerized environments is the effortless recuperation of containers following unplanned downtimes or intentional halts.

To cater to this pivotal need, Docker provides a dependable suite of functionalities termed as “restart policies.”

Grasping Docker’s Restart Rules


Restart policies act as preset norms instructing Docker on the steps to take when a container ceases to function or encounters an error. These rules function as mandates for Docker, guiding it on whether to automatically revive a container or let it stay non-operational. 

Carefully devised restart policies can considerably uplift application dependability and cut back on service interruptions, making certain a seamless comeback from hiccups, system reinitiations, or unpredictable challenges.

Diversity of Restart Guidelines

Docker introduces four main categories of restart policies, each aligned for distinct requirements:

  • No Auto-Restart (no): By default, this guideline directs that the container will not autonomously reboot post-shutdown or malfunction. This is apt for containers where persistent operation isn’t imperative;
  • Reactivate Upon Failure (on-failure): Employing this rule, Docker will only revive the container if there is a failure, commonly signaled by a non-zero termination code. A cap on the number of restart endeavors can also be defined for more adaptability in tackling short-lived problems;
  • Unceasing Reboot (always): Through this policy, Docker ensures that the container will perpetually restart, irrespective of the cause behind its halt. This is most suitable for containers demanding ongoing functionality, like vital services;
  • Resume Except If Halted (unless-stopped): Much like the “always” rule, this option promises that Docker reinitiates the container at startup unless deliberately stopped by the user. It offers a blend of automation and manual intervention.

Setting Up the Restart Guideline


Implementing the restart policy for a Docker container can generally be accomplished through two approaches: at the time of container instantiation or by revising a currently active container.

Tailoring the Restart Rule While Initializing the Container

To tweak the restart policy of an active container, the docker update operation can be invoked alongside the –restart parameter followed by the updated policy. For instance, to alter the restart rule for an active container tagged as “my-container” to “on-failure,” permitting a ceiling of 5 restarts, this command can be executed:

docker update --restart on-failure:5 my-container

Adjusting the Restart Norm for a Live Container

To revise the restart rule for a container that’s already in operation, the docker update function with the –restart parameter and the revamped policy can be employed. For example, to modify the restart policy for a container named “my-container” to “on-failure” and enable up to 5 restarts, this command is appropriate:

docker update --restart on-failure:5 my-container

Final Thoughts


Restart policies stand as an integral facet of Docker’s operational ecosystem, contributing to the resilience and uptime of containers. Gaining a solid grasp of the varying types of restart rules and their implementation methodologies empowers you to fortify app sturdiness and mitigate service disruptions.

Be it the administration of a lone container or the governance of an intricate, multi-container setup, restart policies are essential assets for ensuring the functionality and continuity of your Docker-centric infrastructures. Leverage these rules to bolster the dependability of your Docker deployments and guarantee unbroken service provision.