Running script at dockerfile for node image

Viewed 179

I'm trying to run script file at dockerfile to node project. That script is adding themes repos to the core project - where the dockefile is built and running- . But when trying to run the dockerfile it shows me this error: #12 0.563 /bin/sh: ./script.sh: not found

script.sh

#!/bin/bash
while read p; do
  node tm add $p
done <Themes.txt

dockerfile

FROM node:14
WORKDIR /app
COPY package.json /app
RUN npm install
COPY script.sh /app
COPY Themes.txt /app
RUN chmod +x script.sh
RUN ./script.sh
COPY . /app
EXPOSE 8000
ENTRYPOINT ["npm", "start"]

Themes.txt

theme1-github-repo
theme2-github-repo

Any help please for this also double check the files if they are executing my goal or not ?

1 Answers

This is just a POSIX vs. Bash issue, given you are certainly using an image based on Alpine Linux, in which Bash is not the default shell and it even isn't installed by default.

To overcome this, two alternative solutions:

  • Change your script's shebang to #!/bin/sh (and to be sure you don't use any "bashism", you may want to systematically run the shellcheck linter tool on your script code with this shebang).
  • Keep a (#!/bin/bash or) #!/usr/bin/env bash shebang, but install the bash package in your image beforehand: RUN apk add --no-cache bash
Related