Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All Docker container statuses?

Tags:

docker

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
  • and so on...

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.

like image 947
igr Avatar asked Dec 26 '15 14:12

igr


People also ask

How many states are there of docker containers?

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.

How do I list all containers in docker?

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.


1 Answers

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:

  • Up 1 day (paused)
  • Restarting (123) 1 day ago
  • Up 1 day
  • Removal in Progress
  • Dead
  • Created
  • Exited (123) 1 day ago
  • (empty string)

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"
}
like image 198
helmbert Avatar answered Sep 28 '22 06:09

helmbert