Can cURL send requests to sockets?

The feature was added in curl 7.40.

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

Another example:

curl --no-buffer -XGET --unix-socket /docker.sock http:/events

Which specifies the GET explicitly (rather than assumed). And will not buffer (for tail -f realtime update).

(The first Ubuntu release to ship with curl 7.40 or newer was 15.10).

cURL 7.50 and up requires a valid URL to be provided, including a hostname, so to run the above examples with cURL 7.50, a "dummy" hostname has to be added, for example:

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

and

curl --no-buffer -XGET --unix-socket /docker.sock http://localhost/events

Not sure, but as per this ticket:

  • http://sourceforge.net/p/curl/feature-requests/53/

it doesn't seem to be the case.

Per this:

  • https://gist.github.com/nuxlli/7553996

seems like socat or nc can do it, snip from the above snip:

# Socat version
echo -e "GET /images/json HTTP/1.1\r\n" | socat unix-connect:/var/run/docker.sock STDIO

# nc version (netcat-freebsd)
echo -e "GET /images/json HTTP/1.0\r\n" | nc -U /var/run/docker.sock

Haven't tried either myself.

Tags:

Sockets

Curl