问题描述
我正在尝试使用以下命令将unix套接字公开为tcp套接字:
I am trying to expose a unix socket as a tcp socket using this command:
nc -lkv 44444 | nc -Uv /var/run/docker.sock
当我尝试访问 localhost:44444 / containers / json ,它不加载任何东西,但保持连接打开(加载的东西一直在旋转),但是控制台(由于-v标志)显示正确的http响应。
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:我知道我可以使用socat,或者只是告诉docker也监听tcp套接字,但是我正在使用项目原子vm映像,它不允许我修改/ home以外的任何内容。
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.
推荐答案
您仅重定向输入数据,而不重定向输出数据。
尝试:
You are only redirecting incoming data, not outgoing data.try with:
mkfifo myfifo
nc -lkv 44444 <myfifo | nc -Uv /var/run/docker.sock >myfifo
请参见
编辑::在脚本中,您想随机生成fifo的名称,并在打开后将其删除:
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
这篇关于使用Netcat将Unix套接字通过管道传输到TCP套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!