Weird error, "exec /docker-entrypoint.sh: no such file or directory" but the file is there?!?

Hello all.

We’ve got a Docker Compose stack and we cannot for the life of us start this thing without getting the following error:

Our Dockerfile:

# Build stage
FROM node:16 as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . ./
RUN npm run build

# Production stage
FROM nginx:alpine
COPY --from=build ./build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Install envsubst and ensure proper line endings
RUN apk add --no-cache gettext dos2unix

# Copy and prepare entrypoint script
COPY docker-entrypoint.sh ./docker-entrypoint.sh
RUN dos2unix ./docker-entrypoint.sh && chmod +x ./docker-entrypoint.sh

# Set default environment variable
ENV BACKEND_URL=http://backend.example.com:5001

EXPOSE 80
ENTRYPOINT ["./docker-entrypoint.sh"] 

docker-compose.yml

version: '3'
services:
  frontend:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8006:80"
    environment:
      - BACKEND_URL=http://backend.example.com:5001  # Replace with your actual backend URL
    restart: unless-stopped
    networks:
      - frontend-network

networks:
  frontend-network:
    driver: bridge

docker-entrypoint.sh

#!/bin/sh
set -e

# Replace environment variables in nginx configuration
envsubst < /etc/nginx/conf.d/default.conf > /etc/nginx/conf.d/default.conf.tmp
mv /etc/nginx/conf.d/default.conf.tmp /etc/nginx/conf.d/default.conf

# Start nginx
exec nginx -g 'daemon off;' 

We HAVE a docker-entrypoint.sh file at the root of our Git repo, but try as we might, nothing we have done is working. I have no idea what to do here - none of our changes has resulted in any different error messages and I cannot for the life of me see why it cannot see a file that’s right there in the root.

If you need to use dos2unix, you probably have a file edited on Windows and I never used dos2unix, since modrn editors on Windows can edit Linux compatible files, but if you have Windows line ending at the end of the first line, the shebang line will be invalid and you will get exactly the error message you got. So try an IDE or editor that can show if your file has CRLF (Windows line ending) or LF (Linux line ending) and use only LF in shell scripts.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.