From 356467b61898f746c17a391e9b4be455a763a486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Sat, 30 Jan 2021 16:43:23 +0100 Subject: [PATCH] fix(dockerfile, docker-compose.yaml): add wait for db and redis to server container When starting the server via docker-compose currently the server starts up faster than the postgres instance. This causes the server app to crash. The fix now adds a wait script that pings the database and the cache containers unit they properly start up. This delays the server boot until all deps are started. --- Dockerfile | 4 +++- docker-compose.yaml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f712742f9..fb548aaba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,8 @@ RUN npm run build FROM node as runtime RUN apk add --no-cache tini=0.19.0-r0 +ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait +RUN chmod +x /wait # Use a non-root user for increased security. USER node @@ -54,4 +56,4 @@ COPY --chown=node packages/server /home/node/server # Init for containers https://github.com/krallin/tini ENTRYPOINT [ "/sbin/tini", "--" ] -CMD ["node", "bin/www"] +CMD /wait && node bin/www diff --git a/docker-compose.yaml b/docker-compose.yaml index 2c20ae878..cf7183ee4 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,6 +10,7 @@ services: - "3000:3000" environment: DEBUG: "speckle:*" + WAIT_HOSTS: database:5432, redis:6379 env_file: - .env