Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garystafford/43e0780ef49aa6da76cb to your computer and use it in GitHub Desktop.
Save garystafford/43e0780ef49aa6da76cb to your computer and use it in GitHub Desktop.
Start-up script to eliminate potential race condition between the MongoDB data Docker container and the Node.js web-application container in a 'Dockerized' MEAN application. (post: http://wp.me/p1RD28-1ja)
#!/bin/sh
# Start-up script from inside web_1 (web-application) container
# Gary A. Stafford
# https://github.com/garystafford
# great references:
# Docker Networking Made Simple or 3 Ways to Connect LXC Containers
# (https://blog.codecentric.de/en/2014/01/docker-networking-made-simple-3-ways-connect-lxc-containers)
# Docker 101: Dockerizing Your Infrastructure (http://youtu.be/4W2YY-qBla0)
polling_interval=3
echo "wait for mongo to start first..."
# optional, view db_1 container-related env vars
env | grep DB_1 | sort
# wait until mongo is running in db_1 container
until nc -z $DB_1_PORT_27017_TCP_ADDR $DB_1_PORT_27017_TCP_PORT
do
echo "waiting for $polling_interval seconds..."
sleep $polling_interval
done
# start node app
grunt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment