exec `curl --unix-socket /var/run/docker.sock http:/containers/json` 时出现“404 页面未找到”

wor*_*dcc 3 docker docker-api

docker version: 1.11.2
curl version: 7.50.3 (x86_64-pc-linux-gnu) libcurl/7.50.3 OpenSSL/1.0.1e zlib/1.2.7
Run Code Online (Sandbox Code Playgroud)
/usr/local/sbin/bin/curl  --unix-socket /var/run/docker.sock http://images/json -v
*   Trying /var/run/docker.sock...
* Connected to images (/var/run/docker.sock) port 80 (#0)
> GET /json HTTP/1.1
> Host: images
> User-Agent: curl/7.50.3
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Thu, 22 Sep 2016 06:11:52 GMT
< Content-Length: 19
< 
404 page not found
* Curl_http_done: called premature == 0
* Connection #0 to host images left intact
Run Code Online (Sandbox Code Playgroud)

我的 docker 守护进程有什么问题吗?如何从 docker unix-socket 获取容器信息?docker deamon 绝对启动。

wor*_*dcc 7

我关注了这个页面:https : //docs.docker.com/engine/reference/api/docker_remote_api/#/v1-23-api-changes,它建议我们使用 curl 7.40 或更高版本, command curl --unix-socket /var/run/docker.sock http:/containers/json。你可以发现http:/containers/json这个命令中有一个unavild URL 。

然后我下载了最新的curl 7.50.3,这个问题的关键是curl的版本,我们应该像下面这样执行:

curl --unix-socket /var/run/docker.sock http://localhost/images/json
Run Code Online (Sandbox Code Playgroud)

更多细节观看此页面。https://superuser.com/questions/834307/can-curl-send-requests-to-sockets。希望它可以帮助其他一些困惑的人。

  • 是的。这正是我刚刚在评论部分写的内容 :) 由于您使用的是 curl 7.50,因此它强制您使用有效的 URL。以前它似乎已经接受了单、双、三等分;和一些带有双冒号的 url (http::/)。现在所有这些都已修复(这仅适用于使用 unix 套接字时使用 curl 的情况)。 (3认同)