Using netcat to connect a Unix socket to a tcp socket

I am trying to open a unix socket as a tcp socket with this command:

nc -lkv 44444 | nc -Uv /var/run/docker.sock 

When I try to access localhost:44444/containers/json from the browser, it doesn’t download anything, but keeps the connection open (the download still holds), but the console (due to the -v flag) shows the correct HTTP response.

Any ideas on how to do this?

PS: I know I can use socat or just tell docker to listen on the tcp socket as well, but I am using the atomic image of the vm project and it will not let me change anything other than / home.

+5
source share
1 answer

You only redirect incoming data, not outgoing data. try:

 mkfifo myfifo nc -lkv 44444 <myfifo | nc -Uv /var/run/docker.sock >myfifo 

See http://en.wikipedia.org/wiki/Netcat#Proxying

Edit: in a script, you would like to generate a name for fifo in random order and delete it after opening it:

 FIFONAME=`mktemp -u` mkfifo $FIFONAME nc -lkv 44444 < $FIFONAME | nc -Uv /var/run/docker.sock > $FIFONAME & rm $FIFONAME fg 
+10
source

Source: https://habr.com/ru/post/1200868/


All Articles