Bash can test a TCP port without curl or nc
May 16, 2025
Bash can open TCP connections via /dev/tcp without needing curl, wget, or nc installed.
That’s handy for Docker healthchecks in minimal images:
services:
collabora:
image: collabora/code
healthcheck:
test: bash -c "exec 6<> /dev/tcp/localhost/9980"
interval: 15s
retries: 5
start_period: 60s
timeout: 10s
exec 6<> /dev/tcp/localhost/9980 tries to open file descriptor 6 as a read-write connection to localhost:9980.
If the port isn’t listening, it fails and the healthcheck reports unhealthy.