0

I'm a newbie in docker and planning to automate a docker server using python. Hence I need to know how to check whether the docker is up or not, the container is up or not, server disk space utilization and so on. I need some hints to proceed.

1 Answers1

0

you can use:

import docker
client = docker.from_env()  # to connect using the default socket or the configuration in your environment

client.containers.list()

output:

[<Container: ab0744e975>, <Container: 0acce75faa>]

the above output is just an example from my pc that shows that docker is running and there are 2 containers

or you can use

client.info()

from the docs:

Display system-wide information. Identical to the docker info command.

Returns: The info as a dict Return type: (dict)

Raises: docker.errors.APIError – If the server returns an error.


to check if the system is responsive you can use

client.ping()
Community
  • 1
  • 1
kederrac
  • 16,819
  • 6
  • 32
  • 55