Instantly share code, notes, and snippets.

@nuxlli /
Last active Aug 11, 2018

What would you like to do?
Examples of http request (in unix domain socket) with bash and [nc|socat]
# References
# 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
# bonus round: relay socket
socat -d -d TCP-L:8080,fork UNIX:/var/run/docker.sock

This comment has been minimized.

psi-4ward commented Dec 1, 2016

echo -e "GET /services HTTP/1.0\r\n" | sudo nc -U /var/run/docker.sock | tail -n 1 | jq


This comment has been minimized.

pauldraper commented Sep 3, 2017

(1) You need an extra \r\n to indicate end of headers.
(2) HTTP RFCs don't consider half-closed connections, and many server implementations don't support them. So you may need to keep the socket open.

printf 'GET /images/json HTTP/1.0\r\n\r\n' | nc -q 2 -U /var/run/docker.sock

This comment has been minimized.

rija commented Aug 11, 2018

To get nc -U /var/run/docker.sock working on Debian Jessie, you need to install the netcat-openbsd package because the default netcat package automatically install netcat-traditional that doesnt support Unix Socket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment