The check inspects each running container with the template {{if eq .HostConfig.RestartPolicy.Name "always"}}{{.Name}} {{end}}, so it reads one field, .HostConfig.RestartPolicy.Name, and compares it against a single exact string: always. Every other value is left alone, including unless-stopped, on-failure and no, and .HostConfig.RestartPolicy.MaximumRetryCount is never read, so an on-failure policy passes whether or not it has a retry ceiling. An empty match list is the PASS; otherwise the WARN counts the matching containers and names up to five.
Needs a reachable daemon and at least one running container; otherwise SKIP. It matches one exact value: .HostConfig.RestartPolicy.Name == "always". Nothing else is flagged - notably unless-stopped, which behaves the same as always except after a manual stop, passes this check while providing the same unbounded restart behaviour CIS objects to. no and on-failure (with or without a retry count) also pass. This is an advisory CIS item that many teams deliberately reject; the severity is LOW for that reason.
| Result | When | What it means |
|---|---|---|
| SKIP | No running containers | Nothing was verified. No restart policy was read, so this says nothing about how any container behaves when it crashes. |
| PASS | No container uses always | No running container is set to restart forever, though unless-stopped also passes here and behaves almost identically. |
| WARN | Some use always | The named containers will be restarted indefinitely, so a crash loop can run unnoticed until someone reads the logs. |
This check follows CIS Docker 5.14 "Ensure that the 'on-failure' container restart policy is set to '5'": an unbounded restart loop (always) keeps a crashing or exploited container cycling, consuming CPU and flooding logs, and can hide an attack. on-failure:5 gives up after five attempts so the operator notices.
- Docker's own documentation recommends
unless-stoppedoralwaysfor long-running services so they survive reboots; CIS'son-failure:5means a service that crashes five times at boot (for example because a database dependency is slow) stays down until someone intervenes. Many teams deliberately reject this CIS item and rely on health checks plus alerting instead. Treat as advisory and document the decision. unless-stoppedis functionally the same asalwaysexcept after a manual stop; it is not flagged by this check, so switching to it silences the WARN without changing the restart behaviour that CIS is concerned about.- Docker doubles the wait between restarts, starting at 100 ms and capped at a minute, and resets it once a container stays up for 10 seconds. That slows a tight crash loop but never ends it.
- In Compose, the service-level
restart:key sets this policy;deploy.restart_policyis a Swarm setting.
Find the containers using always
The WARN message names up to five. For the full list:
sh docker inspect -f '{{.Name}} {{.HostConfig.RestartPolicy.Name}}' $(docker ps -q) | grep ' always$'Switch to on-failure with a retry cap
docker updatechanges the policy on a running container without recreating it. Set the same value in Compose, or the nextdocker compose upputsalwaysback.sh docker update --restart on-failure:5 <name>yaml services: app: restart: on-failure:5- Alternative
Or keep a persistent policy with health checks and alerts
If a service must come back after a reboot on its own, keeping
alwaysorunless-stoppedis a defensible choice. Make crash loops visible instead: add aHEALTHCHECK, alert whenRestartCountrises, and record the decision as an accepted exception. Do not switch tounless-stoppedonly to clear this warning. Confirm the policy and restart counts
sh docker inspect -f '{{.Name}} {{.HostConfig.RestartPolicy.Name}}:{{.HostConfig.RestartPolicy.MaximumRetryCount}} restarts={{.RestartCount}}' $(docker ps -q)
docker inspect -f '{{.Name}} {{.HostConfig.RestartPolicy.Name}}:{{.HostConfig.RestartPolicy.MaximumRetryCount}}' $(docker ps -q)# expected under CIS: on-failure:5# Whether restarts are actually happening - usually the more useful signal:docker inspect -f '{{.Name}} restarts={{.RestartCount}}' $(docker ps -q)docker ps --format 'table {{.Names}}\t{{.Status}}' # "Restarting (1) 5 seconds ago" is the red flagdocker inspect -f '{{.Name}} health={{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' $(docker ps -q)- This one message covers two different cases: the audit could not reach the Docker daemon, or it reached it and nothing was running. Run
docker psas the audit user, thensudo docker ps. If both fail, the daemon is unreachable: checksystemctl status docker, then run the audit as root or give the account sudo. If they work but list nothing, there is genuinely nothing to evaluate, and a stopped container is never checked. The Docker Inventory check reports the two cases separately, so its result tells you which one you hit. - The most common outcome. Docker's own guidance recommends
always/unless-stoppedfor long-running services so they survive a reboot, while CIS wantson-failure:5so a repeatedly crashing container stays down and gets noticed. Both positions are defensible; pick one, and if you keepalways, record this as an accepted exception with health checks and restart-count alerting in place. - Worth knowing that this changed almost nothing:
unless-stoppedrestarts just as persistently, it merely remembers a manual stop across daemon restarts. If you were aiming at the CIS intent, useon-failure:5. - A slow dependency, such as a database not yet listening, can use up all five attempts. Add a
HEALTHCHECKanddepends_on: condition: service_healthy, or make the entrypoint wait for its dependency, before adopting the CIS setting. - The restart policy is hiding the real fault.
docker logs --tail 50 <name>anddocker inspect -f '{{.State.ExitCode}} {{.RestartCount}}'show why. Docker's growing delay between restarts keeps the CPU cost of a tight loop low, but the loop itself goes on until the cause is fixed. docker updatechanges the running container only. When Compose next recreates it, therestart:value in the Compose file wins, so setrestart: on-failure:5there as well.
