All Docker container statuses?

The list of Docker statuses is here . However, when I list docker containers using the API, statuses are displayed in "natural" sentences; eg:.

  • Exited (0) NN seconds ago
  • Up NN days
  • etc.

I could not find the final list of all string outputs for all statuses. In other words, I want to parse the docker API status lines.

What are all the possible Docker API outputs for container statuses?

Here is the api I'm talking about.

+8
source share
3 answers

The logic used to create the status summary can be found in the source code for Docker in the file container/states.go , l. 41ff. . Basically, you will get one of the following values:

  • Up to 1 day (suspended)
  • Reboot (123) 1 day ago
  • Up to 1 day
  • Deletion in progress.
  • Dead
  • Created
  • Logout (123) 1 day ago
  • (empty line)

To get machine-readable output, I would suggest using the /containers/:id/json endpoint , which will return a data structure, for example the following:

 "State": { "Dead": false, "Error": "", "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "OOMKilled": false, "Paused": false, "Pid": 2593, "Restarting": false, "Running": true, "StartedAt": "2015-12-26T19:22:38.616937722Z", "Status": "running" } 
+3
source

I have not used the remote API, but I am sure that you really want to get the identifier of all containers, and then get the State information for each container using /containers/(id)/json :

 ... "State": { "Error": "", "ExitCode": 9, "FinishedAt": "2015-01-06T15:47:32.080254511Z", "OOMKilled": false, "Paused": false, "Pid": 0, "Restarting": false, "Running": true, "StartedAt": "2015-01-06T15:47:32.072697474Z", "Status": "running" }, ... 

Thus, you will receive the same data in a much more standard form.

0
source

From your documents

One of created, restarting, running, removing, paused, exited, or dead

In my experience, immediately when you start the container, it is created , then running , then when it exits with a zero or non-zero exit code, it is exited .

0
source

Source: https://habr.com/ru/post/1239252/


All Articles