wait-for-it and dockerize -wait: Wait for TCP Ports
wait-for-it.sh host:port -- cmd waits for a TCP port to open, then runs the command; dockerize -wait tcp://host:port does the same for containers.
Compose stacks and multi-service CI jobs need one service to wait for another. wait-for-it.sh is a dependency-free bash script; dockerize bundles the same wait plus template rendering for container entrypoints.
What it does
wait-for-it.sh opens a TCP connection to host:port in a loop until it succeeds or a timeout expires, then optionally executes the command after --. dockerize -wait <url> waits for one or more resources (tcp://, http://, file://) with a -timeout, then runs its command. Both are TCP-reachability gates, not application-health checks.
Common usage
./wait-for-it.sh db:5432 -t 30 -- npm test
./wait-for-it.sh api:8080 --strict --timeout=60 -- ./run-e2e.sh
# dockerize as an entrypoint wait
dockerize -wait tcp://db:5432 -timeout 30s ./start.sh
dockerize -wait http://api:8080/health -timeout 60s ./run.shOptions
| Flag | What it does |
|---|---|
| host:port | Target to wait for (wait-for-it) |
| -t, --timeout <sec> | Timeout in seconds (0 = wait forever) |
| -s, --strict | Only run the command if the wait succeeded |
| -- <command> | Command to exec after the port is up |
| -wait <url> (dockerize) | Resource to wait for (tcp/http/file) |
| -timeout <dur> (dockerize) | dockerize timeout, e.g. 30s |
In CI
These wait for the TCP port to accept a connection, which is not the same as the app being ready to serve requests. For an app that opens its port before it can handle traffic, prefer dockerize -wait http://.../health or wait-on against a real health URL. Use --strict with wait-for-it so the command does not run when the wait times out.
Common errors in CI
wait-for-it prints wait-for-it.sh: timeout occurred after waiting 30 seconds for db:5432 and exits non-zero when the port never opens. Without --strict it still runs the command after a timeout, so tests start against a down service; add --strict. dockerize prints Timeout after 30s waiting on dependencies on the same condition.