Skip to content

Instantly share code, notes, and snippets.

@ivawzh
Last active July 11, 2020 02:39
Show Gist options
  • Save ivawzh/4fe9010cf534deb4456a19809151b818 to your computer and use it in GitHub Desktop.
Save ivawzh/4fe9010cf534deb4456a19809151b818 to your computer and use it in GitHub Desktop.
docker-compose-wait-for-it
version: "3.8"
services:
terminal:
image: sh
link:
- db
# this will wait for db and then execute the next command after each `-s --`
entrypoint: wait-for-it.sh db:5432 -s -- /usr/local/bin/shush exec -- -s -- echo "night moon"
command: sh
environment:
# magic link referring to database service name done by compose
DB_HOST: db
DB_PASSWORD: "must_set"
db:
image: postgres:12-alpine
restart: always
ports:
- "5435:5432"
volumes:
# to preserve database data from docker
- ./tmp/db-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: "must_set"
From whatever
# Install wait-for-it.sh docker-compose to wait on dependent containers e.g. database
RUN apk --no-cache --virtual .build-deps add curl && \
curl https://raw.githubusercontent.com/raphaelahrens/wait-for-it/master/wait-for-it.sh > /usr/local/bin/wait-for-it.sh && \
chmod +x /usr/local/bin/wait-for-it.sh && \
apk del .build-deps
ENTRYPOINT ["/usr/local/bin/shush", "exec", "--"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment