I'm currently working on a project using NestJS, Prisma and PostgreSQL in a dockerized environment. I have a service for api_server
and another one for running postgres
. I want to run migration before the api_server
starts. So I tried to use this in the Dockerfile of api_server
FROM node:16.13.0-alpine
# Set user and working directory
# Working directory needs to be under /home/node
USER node
WORKDIR /home/node/server
COPY package.json .
# Install node dependencies
RUN yarn
COPY . ./
RUN yarn generate
# the original migration command is kept on the package.json
RUN yarn migrate
EXPOSE 4000
CMD ["yarn", "start:dev"]
But it seems that during the build step of images, none of the services is up. So it throws an error because it can not establish a database connection. What could be a good solution to this problem?