Docker Community Forums

Share and learn in the Docker community.

Control startup and shutdown on docker

Hello I’m having trouble adding a script to my docker file and my docker compose for my pg and my alpine node

my script.sh:

until psql -c '\l'; do

  echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is unavailable - sleeping"

  sleep 1

done

echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is up - executing command"

exec ${@}

my docker file:

#building code

FROM node:lts-alpine

RUN mkdir -p /home/node/api && chown -R node:node /home/node/api

WORKDIR /home/node/api

COPY ormconfig.json .env package.json yarn.* ./

COPY ./wait-pg.sh /

USER node

RUN yarn

COPY --chown=node:node . .

EXPOSE 4000

CMD ["yarn", "dev"]

**my docker compose**

version: '3.7'
services:
  ci-api:
build: .
container_name: ci-api
volumes:
  - .:/home/node/api
  - /home/node/api/node_modules
ports:
  - '${SERVER_PORT}:${SERVER_PORT}'
depends_on:
  - db-pg
logging:
  driver: 'json-file'
  options:
    max-size: '10m'
    max-file: '5'

  db-pg:
image: postgres:12
container_name: db-pg
ports:
  - '${DB_PORT}:5432'
environment:
  ALLOW_EMPTY_PASSWORD: 'no'
  POSTGRES_USER: ${DB_USER}
  POSTGRES_PASSWORD: ${DB_PASS}
  POSTGRES_DB: ${DB_NAME}
volumes:
  - ci-postgres-data:/data
command: ['./wait-pg.sh', 'yarn', 'dev']

volumes:
  ci-postgres-data:

but i got this error:

db-pg | /usr/local/bin/docker-entrypoint.sh: line 315: /wait-pg.sh: No such file or directory

i’m not sure how to add my script to my dockerfile

my folder structure: