Skip to content

wait-for shell script (to be used in `docker-compose.yml` file)

License

Notifications You must be signed in to change notification settings

vnegrisolo/wait-for

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

wait-for

wait-for is a shell script that wait for multiple host:port.

If you want to control startup order for your docker containers you should use this script.

This is a nice Docker documentation about the startup-order problem.

This is script was heavily inspired on this one 👍.

Usage

Using default timeout of 15 seconds:

./wait-for pg.dev:5432

Setting a timeout:

./wait-for --timeout=60 pg.dev:5432
./wait-for -t=5 pg.dev:5432

Wait for multiple host:port:

./wait-for pg.dev:5432 api.dev:3000

Setting different timeouts for each host:port:

./wait-for -t=5 pg.dev:5432 -t=10 api.dev:3000

Main features

  • timeout => in seconds
  • multiple => host:port tuples
  • parallel => wait for better metrics
  • log => some nice log
  • shell => doesn't require anything special

Example of usage:

Here it is a simple example of docker-compose.yml file with two services:

# docker-compose.yml
version: "3"
services:
  web_dev:
    build: .
    command: >
      sh -c '
        bin/wait-for pg.dev:5432 &&
        bundle exec rails server
      '
    ports:
      - "3000:3000"
    links:
      - db_dev:pg.dev

  db_dev:
    image: postgres
    ports:
      - "5432:5432"

Note that I used links entry to define the host to be used in the linked container.

Also I had to use sh -c '...' in order to run multiple shell commands.

About

wait-for shell script (to be used in `docker-compose.yml` file)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages