4
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
/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

Is there anything wrong with my docker daemon? How can I get the containers info from the docker unix-socket? docker deamon is absolutely started.

workhardcc
  • 1,270
  • 3
  • 12
  • 21
  • Use the **--verbose** command line option to see if curl has more information to say anything about it. Also try using double slashes with http (I hope it didn't get mangled in your edit while posting here). – blackpen Sep 22 '16 at 05:05
  • 1
    Use only one slash is followed this page: https://docs.docker.com/engine/reference/api/docker_remote_api/#/v1-23-api-changes. Try to using double slashes with http I get the same result. – workhardcc Sep 22 '16 at 06:11
  • I see your point. There is a relevant discussion [here](https://github.com/curl/curl/issues/936) about how curl-with-sockets used to work with one,two,three slashes. Now (from curl 7.50), the behavior has been changed to require valid **http urls** (fixed). Either way, now that discussions is slightly off-topic. – blackpen Sep 22 '16 at 07:47
  • Since, valid urls should work from curl 7.50, it makes sense that they may also force you to use a some dummy domain name in your URL, do you want to give it a try with `http://localhost/images/json`, because "connecting to images" looks strange to me. – blackpen Sep 22 '16 at 07:50

1 Answers1

8

I followed this page:https://docs.docker.com/engine/reference/api/docker_remote_api/#/v1-23-api-changes, its suggestion us to use curl 7.40 or later, command curl --unix-socket /var/run/docker.sock http:/containers/json. You can found that there is a unavild URL http:/containers/json in this command.

Then I download the newest curl 7.50.3, the key of this problem is the curl's version, we should exec like below:

curl --unix-socket /var/run/docker.sock http://localhost/images/json

More detail watch this page.https://superuser.com/questions/834307/can-curl-send-requests-to-sockets. Hope it help some other people who confused.

Community
  • 1
  • 1
workhardcc
  • 1,270
  • 3
  • 12
  • 21
  • 3
    Yep. That's exactly what I just wrote in comments section :) Since you are using curl 7.50, it forces you to use valid URLs. Previously it seems to have accepted single, double, triple slases; and some urls with double colons (http::/). All that has been fixed now (This applies only for working with curl while using unix sockets). – blackpen Sep 22 '16 at 07:52
  • Thanks a lot, seems I didn't refreash this page cause I see your answer just this moment. It's really good feel to solved this problem. – workhardcc Sep 22 '16 at 08:55