Skip to content
Latchkey

socat: Usage, Options & Common CI Errors

socat relays bytes between any two endpoints - sockets, files, pipes, TTYs.

socat is netcat on steroids: it connects two addresses of almost any type, which makes it the tool for port-forwards and bridging a UNIX socket to TCP in CI. Its address syntax is the learning curve.

What it does

socat opens two "address" channels (TCP, UDP, UNIX sockets, files, STDIO, EXEC, …) and shuttles data between them bidirectionally. It is the general-purpose relay used to forward ports, expose UNIX sockets over TCP, and proxy connections.

Common usage

Terminal
socat - TCP:localhost:6379                      # interactive client
socat TCP-LISTEN:8080,fork TCP:backend:80       # simple TCP forwarder
socat TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock
socat UNIX-LISTEN:/tmp/s.sock,fork TCP:host:5432
echo "PING" | socat - TCP:host:6379

Options

Address / itemWhat it does
TCP:host:portConnect out to a TCP endpoint
TCP-LISTEN:portListen for inbound TCP
UNIX-CONNECT / UNIX-LISTENConnect to / listen on a UNIX socket
-STDIO (your terminal/pipe)
forkHandle each new connection in a child
reuseaddrAllow immediate re-bind of the port

Common errors in CI

"socat ... E ... bind: Address already in use" - a previous socat (or the real service) still holds the port; add reuseaddr or stop it. Without fork, a LISTEN address handles one connection then exits, so the second client gets refused - add ,fork for a persistent forwarder. "socat: command line ... unknown option" usually means lowercase/uppercase or comma-option mistakes (options attach to the address with commas, e.g. TCP-LISTEN:80,fork,reuseaddr). A UNIX-CONNECT to a missing socket gives "No such file or directory".

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →