Docker Remote API Filter Exited

后端 未结 3 954
猫巷女王i
猫巷女王i 2020-12-30 12:42

I see in the Docker Remote API Docs that filter can be used to filter on status but I\'m unsure how to form the request:

https://docs.docker.com/reference/api/docker

3条回答
  •  佛祖请我去吃肉
    2020-12-30 13:17

    jwodder is correct on the filter but I wanted to go through this step by step as I wasn't familiar with the Go data types.

    The Docker API documentation refers to using a map[string][]string for a filter, which is a Go map (hash table)

    • map[string] defines a map with keys of type string

    • []string is the type definition for the values in the map. A slice [] is an array without fixed length. Then the slice is made up of string values.

    So the API requires a hash map of arrays containing strings. This Go Playground demonstrates marshalling the Go filter data:

    mapS := map[string][]string{ "status":[]string{"exited"} }
    

    Into JSON:

    { "status": [ "exited" ] }
    

    So adding that JSON to the Docker API request you get:

    GET /containers/json?all=1&filters={%22status%22:[%22exited%22]}
    

    all=1 is included to report exited containers (like -a on the command line).

    It might be easier for non Go people if they just documented the JSON structure for the API : /

提交回复
热议问题