def test_can_pop_new_container(self):
config = {
'ip': '10.49.0.2',
'subnet': '10.49.0.0/16',
'gateway': '10.49.0.202',
'vlan': 102,
'hostname': 'test-container',
}
container = container_services.pop_new_container(config, self.docker_api)
inspection = self.docker_api.inspect_container(container.get('Id'))
print('before', inspection.get('RestartCount'), inspection.get('StartedAt'))
container_services.restart(container, self.docker_api)
new_inspection = self.docker_api.inspect_container(container.get('Id'))
print('after', new_inspection.get('RestartCount'), new_inspection.get('StartedAt'))
def restart(container, docker_client):
return docker_client.restart(container.get('Id'))
From the test I get
before 0 None
after 0 None
From docker ps
that confirm the container restarted.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
86f16438ffdd docker.akema.fr:5000/coaxis/coaxisopt_daemon:latest "/usr/bin/supervis..." 28 seconds ago Up 17 seconds confident_dijkstra
Why is RestartCount
still at 0
then? Am I using the wrong field?
As already indicated in the comment, the field RestartCount
is used in the context of Restart Policies to keep track of restart attempts in case of failures.
It will not be incremented in case of user-initiated restarts.
You can look at docker events to keep track on normal container restarts. This is also available for dockerpy.