My project directory structure:
myapp/
src/
Dockerfile
docker-compose.yml
docker-deploy.sh
wait-for-it.sh
.env
Where wait-for-it.sh is a copy of the famous wait-for-it script.
My Dockerfile:
FROM node:16
WORKDIR /usr/src/app
COPY package*.json ./
COPY wait-for-it.sh ./
COPY docker-deploy.sh ./
RUN chmod +x docker-deploy.sh
RUN npm install --legacy-peer-deps
COPY . .
RUN npm run build
ENTRYPOINT ["docker-deploy.sh"]
And docker-deploy.sh is:
#!/bin/bash
# make wait-for-it executable
chmod +x wait-for-it.sh
# call wait-for-it with passed in args and then start node if it succeeds
bash wait-for-it.sh -h $1 -p $2 -t 300 -s -- node start
And my docker-compose.yml:
version: '3.7'
services:
my-service:
build: .
postgres:
container_name: postgres
image: postgres:14.3
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USER}
POSTGRES_DB: my-service-db
PG_DATA: /var/lib/postgresql2/data
ports:
- ${DB_PORT}:${DB_PORT}
volumes:
- pgdata:/var/lib/postgresql2/data
volumes:
pgdata:
And where my .env looks like:
DB_PASSWORD=1234
DB_USER=root
DB_PORT=5432
When I run the following command-line from the project root:
docker-compose --env-file .env up --build
I get:
Creating myapp_my-service_1 ... error
Creating postgres ...
Creating postgres ... done
ERROR: for my-service Cannot start service my-service: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "docker-deploy.sh": executable file not found in $PATH: unknown
ERROR: Encountered errors while bringing up the project.
What is going on? Is the error coming from the wait-for-it.sh script itself, from a poorly configured CMD directive in the Dockerfile, or from the actual Node/JS app running as my-service?
Update
Latest errors after applying @ErikMD's suggested changes:
Creating postgres ... done
Creating myapp_my-service_1 ... error
ERROR: for myapp_my-service_1 Cannot start service my-service: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "./docker-deploy.sh": permission denied: unknown
ERROR: for my-service Cannot start service my-service: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "./docker-deploy.sh": permission denied: unknown
ERROR: Encountered errors while bringing up the project.
So it is spinning up the DB (postgres) no problem but is still for some reason getting permissions-related issues with the docker-deploy.sh script.
node ./wait-for-it.shCan you try usingENTRYPOINTinstead ofCMD?wait-for-it.shis actually an executable? If not,CMD ["./wait-for-it.sh", ...]might not be interpreted correctly as "exec form" of CMD but as "param from" thus, all the parameters passed on to the defaultENTRYPOINTof the container which is thenodeexecutable (and which would fit the observed behaviour)docker-deploy.shscript and invoking that from anENTRYPOINT, which seems to be a common-ish practice, but still problems!ENTRYPOINTlooks weird; please tryENTRYPOINT ["./docker-deploy.sh"].