The list of Docker statuses is here. However, when I list docker containers using the API, the statuses are shown in 'natural' sentences; e.g.:
Exited (0) NN seconds ago
Up NN days
I couldn't find the definitive list of all string outputs for all the statuses. In other words, I want to parse docker API status strings.
What are all the possible outputs of the Docker API for container statuses?
Here is the api Im talking about.
Container states – A container can be in one of four states: running, paused, exited, restarting. Containerization – Use of operating system level process isolation. Low overhead because a guest operating system is not required. Daemon – A process that runs in the background.
In order to list the Docker containers, we can use the “docker ps” or “docker container ls” command. This command provides a variety of ways to list and filter all containers on a particular Docker engine.
The logic by which the status summary is generated can be found in the Docker source code, in the file container/states.go
, l. 41ff.. Basically, you'll get one of the following:
In order to get a machine-readable output, I'd suggest using the /containers/:id/json
endpoint, which will return a data structure like 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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With