Last active
July 11, 2020 02:39
-
-
Save ivawzh/4fe9010cf534deb4456a19809151b818 to your computer and use it in GitHub Desktop.
docker-compose-wait-for-it
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: "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" |
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 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