Coder Social home page Coder Social logo

wait_for_port's Introduction

wait_for_port is a simple container to do one thing: wait until a specified container is listening on a port.

If the port is 5432, it also attempts to log in to Postgres with the given credentials, since Postgres can be listening on port 5432 but still not yet really ready to serve requests.

Examples

docker run --rm --name wfp -v /var/run/docker.sock:/var/run/docker.sock \
    wait_for_port \
    --container somecontainer \
    --port 12345 \
    --timeout 10

Run the container and wait for container somecontainer to start listening on port 12345. Time out after 10 seconds.

docker run --rm --name wfp -v /var/run/docker.sock:/var/run/docker.sock \
    wait_for_port \
    --container somedbcontainer \
    --port 5432 \
    --timeout 100 \
    --pg_database "$POSTGRES_DB" \
    --pg_user "$POSTGRES_USER" \
    --pg_password "$POSTGRES_PASSWORD"

Run the container and wait for container somedbcontainer to start listening on port 5432 and accept the credentials to connect to the database. Time out after 100 seconds.

Use-Case

When using crane (or docker-compose, or similar), use a post-start hook to ensure a container is started after the container(s) it depends on is/are listening for incoming connections.

containers:
  slowstartingcontainer:
    build: {...}
    image: company.org/slowstartingcontainer
    run: {...}

  dependentcontainer:
    build: {...}
    image: company.org/dependentcontainer
    run:
      ...
      link:
        - slowstartingcontainer
      ...

hooks:
  slowstartingcontainer:
    post-start: "docker run --rm --name wfp -v /var/run/docker.sock:/var/run/docker.sock wait_for_port:latest --container slowstartingcontainer --port=12345 --timeout=3600"

wait_for_port's People

Contributors

olliemath avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.