10

I am trying to expose a unix socket as a tcp socket using this command:

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

When I try to access localhost:44444/containers/json from a browser, it doesn't load anything but keeps the connection open (the loading thingy keeps spinning), but the console (because of the -v flag) shows proper http response.

Any ideas on how to get this working?

PS: I know I can use socat, or just tell docker to also listen on a tcp socket, but I am using the project atomic vm image, and it won't let me modify anything except /home.

2
  • your browser is expecting a proper http response, which is a header block followed by body content. until your stuff outputs at least one blank line, the browser will never see "body" content and just sit there waiting. Commented Aug 21, 2014 at 18:17
  • 3
    Pipes only go one way... the netcat on the left isn't going to get the output from the netcat on the right. The netcat on the left is reading from your original stdin (terminal?) Commented Aug 21, 2014 at 18:29

1 Answer 1

16

You are only redirecting incoming data, not outgoing data. try with:

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 want to generate the name for the fifo at random, and remove it after opening it:

FIFONAME=`mktemp -u`
mkfifo $FIFONAME
nc -lkv 44444 < $FIFONAME | nc -Uv /var/run/docker.sock > $FIFONAME &
rm $FIFONAME
fg
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! That works great. Also, I am stupid X-D. Just to add something small to your answer, I ran 2 commands: rm -f /tmp/myfifo; mkfifo /tmp/myfifo && nc -lkv 44444 </tmp/myfifo | nc -Uv /var/run/docker.sock >/tmp/myfifo .
If you are scripting this, use mktemp -u to generate a name which is guaranteed to be a non-existant file
nice, i use this to open my docker remote port 2375

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.