我在过滤器可用于对状态筛选泊坞远程API文档看,但我不能确定如何形成请求:泊坞远程API过滤器已退出
https://docs.docker.com/reference/api/docker_remote_api_v1.16/#list-containers
GET /containers/json?filters=status[exited] ?????
应该如何这被格式化为只显示退出的容器?
我在过滤器可用于对状态筛选泊坞远程API文档看,但我不能确定如何形成请求:泊坞远程API过滤器已退出
https://docs.docker.com/reference/api/docker_remote_api_v1.16/#list-containers
GET /containers/json?filters=status[exited] ?????
应该如何这被格式化为只显示退出的容器?
jwodder是correct on the filter但我想经历这一步一步,因为我不熟悉Go数据类型。
的Docker API documentation指的是使用map[string][]string
用于过滤器,这是一种围棋地图(哈希表)
map[string]
限定了地图类型string
[]string
的键是类型定义为地图中的值。片 []
是一个没有固定长度的数组。然后该切片由 string
值组成。
所以API需要包含字符串的数组的哈希映射。这Go Playground演示编组转到过滤数据:
mapS := map[string][]string{ "status":[]string{"exited"} }
为JSON:
{ "status": [ "exited" ] }
所以补充说JSON的多克尔API请求你:
GET /containers/json?all=1&filters={%22status%22:[%22exited%22]}
all=1
包括报告退出的容器(如命令行上的-a
)。/
通过我的文档阅读,它应该是:
GET /containers/json?filters={"status":["exited"]}
一些可能需要进行网址编码,虽然。
什么是对URL进行编码的正确方法? http:// localhost:5555/containers/json?filters = {%27status%27%3A%5B%27exited%27%5D}不起作用。 – 2015-01-20 21:00:36
curl -X GET http:// localhost:5555/containers/json?filters =%7B%22status%22%3A%5B%22exited%22%5D%7D returned curl -X GET http:// localhost :5555/containers/json?all = 1正确返回 – 2015-01-20 21:21:39
使用泊坞窗,卷曲最优雅的方式,并且不与编码我this answer发现麻烦:
如果他们只是记录了JSON结构的API它可能对非围棋的人会更容易。基本上,它告诉curl使用数据作为查询参数并对其进行编码。要获得退出的容器,查询可能如下所示:
curl -G -XGET "http://localhost:5555/containers/json" \
-d 'all=1' \
--data-urlencode 'filters={"status":["exited"]}' | python -m json.tool
我试过在浏览器中使用引号转义并使用curl,但都没有给出结果。如何获得此请求的有效回复? – 2015-01-20 21:49:00
您需要为'exited'添加'all = 1'来报告。回答更新 – Matt 2015-01-20 21:55:51
完美!这就是我所错过的。这对我有效:http:// localhost:5555/containers/json?all = 1&filters = {%22status%22:%5B%22exited%22%5D} – 2015-01-20 22:29:56