I am trying to run a nestjs app that runs on postgres db via typeorm, on docker toolbox. I need to make the backend server wait for the database configurations to finish and open the port so I tried out wait-for shell script. However, its not running and docker logs on backend server container is showing
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
sh: 1: ./bin/wait-for.sh: not found
docker-compose.yml
version: '3.7'
services:
postgresdb:
image: 'postgres'
environment:
POSTGRES_PASSWORD: 'admin'
POSTGRES_USER: 'postgres'
POSTGRES_DB: 'yourcarprod'
PGDATA: '/var/lib/postgresql/data/pgdata'
ports:
- '5432:5432'
networks:
- shared-network
volumes:
- db-config:/etc/postgresql
- db-data:/var/lib/postgresql/data
- ./backend/src/database/backup:/data_backup/data/pgdata
backend-app:
container_name: nestjs_api_prod
image: nestjs-api-image
build:
context: backend
dockerfile: Dockerfile
ports:
- '8000:8000'
env_file:
- ./backend/.env
command: sh -c './bin/wait-for.sh -t 0 postgresdb:5432 -- yarn start:prod'
depends_on:
- postgresdb
restart: unless-stopped
networks:
- shared-network
networks:
shared-network:
volumes:
db-config:
db-data:
Dockerfile
FROM node:16
WORKDIR /usr/src/api
COPY package.json .
COPY yarn.lock .
RUN yarn global add @nestjs/cli
RUN yarn global add ts-node
RUN yarn global add typeorm
RUN yarn install
RUN apt-get -q update && apt-get -qy install netcat
COPY . .
RUN yarn build
CMD ["sh", "-c", "yarn run migration:generate && yarn start:prod"]
modifications in package.json:
...
"scripts": {
...
"start:prod": "cross-env NODE_ENV=production node dist/src/main",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
"migration:generate": "yarn run build && yarn typeorm migration:generate -n CreatedDatabase"
}
...
Folder Structure:
I am a novice in docker and don't have much or almost any knowledge in shell scripting. Any help is greatly appreciated.