Docker远程API过滤器已退出 [英] Docker Remote API Filter Exited
问题描述
https://docs.docker.com/reference/api/docker_remote_api_v1.16/#list容器
GET / containers / json?filters = status [exited]
应如何格式化以显示只有退出的容器?
jwodder 是过滤器上的错误,但是我想逐步了解一下,因为我不熟悉Go数据类型。
是指为过滤器使用一个 map [string] [] string
,这是一个Go map(哈希表)
-
map [string]
定义一个类型为string
-
[] string
是地图中的值。切片
[]
是一个没有固定长度的数组。然后切片由
string
值组成。
所以API需要一个包含字符串的数组的哈希映射。此 Go Playground 演示了汇总Go过滤器数据:
mapS:= map [string] [] string {status:[] string {exited}}
进入JSON:
{status :[exited]}
所以将JSON添加到Docker API请求中: p>
GET / containers / json?all = 1& filters = {%22status%22:[%22exited%22]}
all = 1
包含报告退出的容器
如果他们刚刚记录了JSON,那么非Go人可能会更容易API的结构:/
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_remote_api_v1.16/#list-containers
GET /containers/json?filters=status[exited] ?????
How should this be formatted to display ONLY exited containers?
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 typestring
[]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 ofstring
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 : /
这篇关于Docker远程API过滤器已退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!