Consider the Dockerfile :
Dockerfile :
FROM node:14
COPY . /app
RUN npm i
RUN npm run build_database_migrations <<<<====== This is the problematic command
... more commands
Which uses sequelize-cli
:
In package.json :
"scripts": {
"build_database_migrations": "sequelize db:migrate",
}
And the Docker-compose :
Docker-compose.yaml
version: "3"
services:
postgresql:
image: postgres:latest
environment:
POSTGRES_USER: user1
POSTGRES_PASSWORD: pass1
POSTGRES_DB: somedb
ports:
- "5432:5432"
app:
build:
context: ./employee
dockerfile: ./Dockerfile
ports:
- "9000:9000"
restart: on-failure
depends_on:
- postgresql
links:
- postgresql
Whenever I run the Docker-compose up
the app
never waits for postgresql
to be up and running ,
which results in building the app
container and running the command RUN npm run build_database_migrations
before the Postgreqsql Container is listening on port 5432
.
How can we force the app
Container to wait until Postreqsql
container is ready and listening on port 5432
, so it would be able to run the migrations on a live Postgresql Container ?