HeadlinesBriefing favicon HeadlinesBriefing.com

Bash TCP Sockets Bypass Need for curl in Docker Containers

Hacker News •
×

A developer needed to verify connectivity between containers on a Docker network but hit a wall: the target container ran a stripped-down image with no curl, wget, or networking utilities. Standard HTTP clients were unavailable, making basic health checks impossible with conventional tools.

Bash's `/dev/tcp` pseudo-device solves this niche problem. The feature lets bash open TCP sockets directly using syntax like `exec 3<>/dev/tcp/service/8642`, then write raw HTTP requests to file descriptor 3. No external binaries required—just bash itself handles the DNS lookup and connection. The hostname resolves through Docker's internal networking.

However, this isn't a proper HTTP client. It lacks TLS support, redirect handling, and response parsing. Connection: close is essential to prevent hanging, and TLS requires openssl instead. The feature depends on bash being compiled with `--enable-net-redirections`, which Debian disabled for years.

This trick shines in debugging scenarios where you can't install packages. For production health checks, curl remains the right choice. But when you're trapped in a minimal container and need quick connectivity verification, bash's built-in networking beats adding unnecessary dependencies.