Search code examples
angulardockershellnginxdockerfile

Docker entrypoint script for image build not correct


I am building an Docker-Image for a Angluar Web-App and in the image creation I build the angular boundle using a node-image as base and then copy the dist folder to an nginx webserver. As an entrypoint I use a shellscript that replaces some placeholders in the dist files with environment variables (API-Hostname etc.). The Image builds with no error but when I try to run a container with that image, I get the following error:

run.sh: 1: Syntax error: word unexpected (expecting "do")

My Dockerfile:

FROM node:16 AS build

WORKDIR /app

COPY package*.json ./
COPY src ./src
COPY angular.json ./
COPY tsconfig.app.json ./
COPY tsconfig.json ./

RUN npm install
RUN npm run build-docker


FROM nginx
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /app/dist/[PROJECT NAME] /usr/share/nginx/html

COPY ./docker/run.sh ./run.sh

ENTRYPOINT ["sh", "run.sh"]

The run.sh script:

for mainfile in $(ls /usr/share/nginx/html/main*.js);
do
  envsubst '$HOST_NAME' < $mainfile > main.tmp;
  mv main.tmp $mainfile;
done

nginx -g 'daemon off;'

I can not find any error in this configuration, any ideas?


Solution

  • Just posting the answer here for others to find if needed.

    The Problem was, that I had a semicolon in the run.sh file. At the end of the for loop. So the correct script is:

    for mainfile in $(ls /usr/share/nginx/html/main*.js)
    do
      envsubst '$HOST_NAME' < $mainfile > main.tmp;
      mv main.tmp $mainfile;
    done
    
    nginx -g 'daemon off;'
    

    Thanks to @DavidMaze for the help!