Last active
March 14, 2016 18:07
-
-
Save mycargus/eeb0f5ad4f19c50be5b5 to your computer and use it in GitHub Desktop.
docker-compose: confirm a dependent container is launched and accepting TCP connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
rspec: | |
build: | |
context: . | |
dockerfile: Dockerfile_rspec_example | |
environment: | |
APP_HOST: web.app.docker | |
HUB_HOST: selenium.hub.docker | |
volumes: | |
- .:/usr/src/app | |
depends_on: | |
- web | |
- hub | |
web: | |
image: web-app:latest | |
environment: | |
RAILS_ENV: test | |
VIRTUAL_HOST: web.app.docker | |
hub: | |
image: selenium/hub:2.52.0 | |
environment: | |
VIRTUAL_HOST: selenium.hub.docker | |
ports: | |
- 4444:4444 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ruby:latest | |
USER root | |
ENV APP_HOME /usr/src/app | |
RUN mkdir -p $APP_HOME | |
WORKDIR $APP_HOME | |
RUN apt-get update && apt-get install -y \ | |
netcat-openbsd | |
COPY ./wait $APP_HOME | |
ENTRYPOINT bash wait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Any docker container may use this script to ensure a dependent container is | |
# launched and listening on TCP | |
# args: dependent containers's host address and port | |
set -e | |
host=$HUB_HOST | |
port=$HUB_PORT | |
echo -n "waiting for TCP connection to $host:$port..." | |
while ! nc -w 1 $host $port 2>/dev/null | |
do | |
echo -n . | |
sleep 1 | |
done | |
echo 'ok' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment