1 year ago
#356171
Hellstormer
Expose stdin and stdout of binary as TCP socket in Docker
With socat I can expose a binaries stdin/out as a socket for example like this:
$ socat TCP-LISTEN:8080,fork EXEC:./mybinary,pty
I would like to do the same with for example the go docker image.
But I can't run CMD [ "socat TCP-LISTEN:8080,fork EXEC:/mybinary,pty" ]
because in the go image there is no socat
tool and I see now way to install it.
Full error:
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "socat TCP-LISTEN:8080,fork EXEC:/mybinary,pty": stat socat TCP-LISTEN:8080,fork EXEC:/mybinary,pty: no such file or directory: unknown.
Is there an elegant/intended way to do this in Docker?
Edit: My Docker File: (The project itself is just the most generic stdin/stdout echo-server you could imagine)
FROM golang:1.18
WORKDIR /app
COPY go.mod .
COPY *.go ./
RUN go build -v -o /mybinary
CMD socat TCP-LISTEN:8080,fork EXEC:/mybinary,pty
docker
go
socat
0 Answers
Your Answer