./wait-for
is a script designed to synchronize services like docker containers. It is sh and alpine compatible. It was inspired by vishnubob/wait-for-it, but the core has been rewritten at Eficode by dsuni and mrako.
When using this tool, you only need to pick the wait-for
file as part of your project.
wait-for [host:port...] [-t timeout] [-- command args]
-q | --quiet Do not output any status messages
-l | --loose Execute subcommand even if the test times out
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
To check if eficode.com is available:
$ ./wait-for www.eficode.com:80 -- echo "Eficode site is up"
Eficode site is up
The subcommand will be executed regardless if the service is up or not. If you wish to execute the subcommand only if the service is up, add the --strict argument. In this example, we will test port 81 on www.google.com which will fail:
$ ./wait-for www.google.com:81 --timeout=1 -- echo "google is up"
Operation timed out
$ ./wait-for www.google.com:81 --timeout=1 --loose -- echo "waited for google"
Operation timed out
waited for google
To wait for database container to become available:
version: '2'
services:
db:
image: postgres:9.4
backend:
build: backend
command: sh -c './wait-for db:5432 -- npm start'
depends_on:
- db
To wait for several containers to become available:
version: '2'
services:
db:
image: postgres:9.4
elk:
image: sebp/elk
backend:
build: backend
command: sh -c './wait-for db:5432 elk:9563 -- npm start'
depends_on:
- db
- elk
Ironically testing is done using bats, which on the other hand is depending on bash.
docker build -t wait-for .
docker run -t wait-for
Make sure netcat is installed in your Dockerfile before running the command.
RUN apt-get -q update && apt-get -qy install netcat
https://stackoverflow.com/questions/44663180/docker-why-does-wait-for-always-time-out