Skip to content
A simple script to wait for other docker images to be started while using docker-compose
Rust Shell
Branch: master
Clone or download


Build Status codecov

A small command line utility to wait for other docker images to be started while using docker-compose. It permits to wait for a fixed amount of seconds and/or to wait until a TCP port is open on a target image.


This utility should be used in the docker build process and launched before your application starts.

For example, your application "MySuperApp" uses MongoDB, Postgres and MySql (wow!) and you want to be sure that, when it starts, all other systems are available, then simply customize your dockerfile this way:

## Use whatever base image
FROM alpine

## Add your application to the docker image

## Add the wait script to the image
ADD /wait
RUN chmod +x /wait

## Launch the wait tool and then your application
CMD /wait && /

Done! the image is ready.

Now let's modify the docker-compose.yml file:

version: "3"


    image: mongo:3.4
    hostname: mongo
      - "27017:27017"

    image: "postgres:9.4"
    hostname: postgres
      - "5432:5432"

    image: "mysql:5.7"
    hostname: mysql
      - "3306:3306"

    image: "mySuperApp:latest"
    hostname: mySuperApp
      WAIT_HOSTS: postgres:5432, mysql:3306, mongo:27017

When docker-compose is started (or Kubernetes or docker stack or whatever), your application will be started only when all the pairs host:port in the WAIT_HOSTS variable are available. The WAIT_HOSTS environment variable is not mandatory, if not declared, the script executes without waiting.

If you want to use the script directly in docker-compose.yml instead of the Dockerfile, please note that the command: configuration option is limited to a single command so you should wrap in a sh call. For example:

command: sh -c "/wait && /"

This is discussed further here and here.

Additional configuration options

The behaviour of the wait utility can be configured with the following environment variables:

  • WAIT_HOSTS: comma separated list of pairs host:port for which you want to wait.
  • WAIT_HOSTS_TIMEOUT: max number of seconds to wait for the hosts to be available before failure. The default is 30 seconds.
  • WAIT_BEFORE_HOSTS: number of seconds to wait (sleep) before start checking for the hosts availability
  • WAIT_AFTER_HOSTS: number of seconds to wait (sleep) once all the hosts are available
  • WAIT_SLEEP_INTERVAL: number of seconds to sleep between retries. The default is 1 second.

Using on non-linux systems

The simplest way of getting the wait executable is to download it from{{VERSION}}/wait

This is a pre-built executable for Linux x64 systems which are the default ones in Docker. In addition, it is built with MUSL for maximum portability.

If you need it for a different architecture, you should clone this repository and build it for your target.

As it has no external dependencies, an being written in the mighty rust programming language, the build process is just a simple cargo build --release (well... of course you need to install the rust compiler before...)

For everything involving cross-compilation, you should take a look at Cross. For example, to build for a raspberry pi, everything you have to do is:

  1. Install the latest stable rust toolchain using rustup
  2. Correctly configure Docker on your machine
  3. Open a terminal and type:
    cargo install cross
    cross build --target=armv7-unknown-linux-musleabihf --release
  4. use your new shiny executable on your raspberry device!


This utility was explicitly written to be used with docker-compose; however, it can be used everywhere since it has no dependencies on docker.

You can’t perform that action at this time.