Start Docker containers automatically after a reboot

Choose a restart policy, ensure the daemon starts, and distinguish process restarts from dependency readiness and live restore.

Best practices
Illustration of container operations and troubleshooting

Configure a container restart policy and make sure the Docker daemon itself starts when the host boots. unless-stopped is useful when an intentional stop should remain in effect across a daemon restart.

docker run -d --restart unless-stopped --name myapp myimage:1.2
docker update --restart unless-stopped myapp
docker inspect --format '{{json .HostConfig.RestartPolicy}}' myapp

The update command changes an existing container's policy without rebuilding its image. Keep the same policy in your deployment definition so a later recreation does not undo the change.

Compare policies

Policy Main behavior
no No automatic restart
on-failure[:max-retries] Retry a nonzero process exit, optionally with a limit; not a daemon-restart startup policy
always Restart after exits; a manual stop suppresses restart until the container is started again or the daemon restarts
unless-stopped Similar exit handling, but a stopped container stays stopped across daemon restarts

A policy does not repair an invalid startup command, missing configuration or unhealthy application. Observe restart counts and the actual failure, rather than treating repeated restarts as recovery.

A Compose definition can record the intended behavior:

services:
  app:
    image: myimage:1.2
    restart: unless-stopped

Verify the complete startup path

On a systemd-based Linux Engine host, check the Docker service and enable it at boot if that is the intended host configuration:

systemctl is-enabled docker
sudo systemctl enable docker

Other platforms have different startup mechanisms, including Docker Desktop and rootless Engine. Enabling a system service is not a portable command for every Docker installation.

Arrange a controlled reboot or daemon-restart test in a suitable environment, then check container state and a representative application request. Host restarts and daemon changes can disrupt workloads; they are not necessary merely to inspect a policy.

For an existing Guance HTTP check, compare availability around the test from a probe that can reach the service. Container uptime alone cannot establish end-to-end recovery.

Related mechanisms and FAQ

How does live restore differ? Live restore can keep eligible running containers alive while the daemon is unavailable or upgraded, subject to its platform and configuration constraints. It does not keep them running through a host reboot. A restart policy acts when a container needs to be started again.

Can systemd manage container startup instead? Docker recommends its own restart policies for ordinary container restart needs. A host process manager can be appropriate for other dependency arrangements, but do not let both independently restart the same container.

Will the database start first? Restart policies do not express readiness dependencies. Compose can coordinate dependency health during an explicit up, but that is not a daemon-wide boot ordering guarantee. Applications should tolerate temporary dependency unavailability with bounded retries.

Is a Kubernetes Deployment the same thing? No. Kubernetes has Pod/container restart rules and controllers that maintain desired replicas. Probe behavior, replacement Pods, backoff and rollout settings are separate from Docker's policy names.

See Docker restart policies, Docker live restore, Compose startup and readiness.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting