Docker Community Forums

Share and learn in the Docker community.

Docker restart policy is empty/nul


Has anyone ever reported an issue where containers are running as expected, but the restart policy shown in the docker inspect JSON output is empty / null? here is an example

[root@dockerhostA ~]# docker ps


748bdbb9436c splunk/universalforwarder:7.0.2 “/sbin/entrypoint…” 2 weeks ago Up 2 weeks 1514/tcp, 8088-8089/tcp us-fkl1-prd2-int-glb-splunkforwarder-svc.1vos8qzvw23f8aioq2uajt4i1.m74k78kpr9d36ix9je50efs0i

[root@dockerhostA ~]# docker inspect -f “{{HostConfig.RestartPolicy.Name}}” 748bdbb9436c

[root@dockerhostA ~]#

(Metin Y.) #2

Are you missing the restart policy on a container that was scheduled by a task of a swarm service?
If so, I am currious why you would expect the restart information to be on the container and not on the service?


Why would using swarm to set the restart policy not apply to each specific container in the service?

(Metin Y.) #4

Lets focus on the assumption your post bases on, please :wink:


I would expect each container to have a a restart policy, either set by swarm or by the docker run command. If none is specified, then the default should be applied which is no. In this case there was no policy applied at all. why is that

(Metin Y.) #6

Docker Swarm is an Orchestrator, which operates on service level, not on container level. Thus, it takes care of managing tasks that result in ephemeral containers. Those containers are created, executed once and disposed. Though, not deleted immediatly so you remain able to still query its logs. Instead of restarting a dead/stoped container, a new task is used to create a new ephemeral container. The lifecylce of the container is managed by swarm thru managing the service using task - the container is merly a vehicle to execute the task. If you have a multi host docker cluster, a task could schedule the container on any node. In case a node dies, the container would summoned on a another node. If the restart information would be bound to the container, you might end up with severall restarting containers on your nodes.

While without Swarm, e.g. docker-compose or plain docker create/run, the lifecycle of a container is managed directly.

If you know what the default behavior is, isn’t adding information about the default policy in the inpsect output merly consmetic? The documentation is clear about the default behavior, isn’t it.