Search code examples
bashdockerpm2alpine-linux

Can not run bash script in pm2 on docker alpine image


I have created an image from the following Dockerfile.

FROM alpine
WORKDIR /usr/src/app
RUN apk add nodejs-current
RUN apk add nodejs-npm
RUN npm install pm2 -g
COPY process.yaml .
CMD pm2 start process.yaml --no-daemon --log-date-format 'DD-MM 
HH:mm:ss.SSS'

process.yaml looks like this:

- script: ./run-services.sh
  watch : false

But run-services.sh does not run in my docker. What is the problem?


Solution

  • The problem is that in alpine the bash is not installed by default. pm2 runs bash scripts files by bash command. so there is two way to solve the problem:

    1. Changing default pm2 interpreter from bash to /bin/sh

      - script: ./run-services.sh
        interpreter: /bin/sh
        watch : false
      
    2. Installing bash in alpine. So the Dockerfile changes as following:

      FROM alpine
      RUN apk update && apk add bash
      WORKDIR /usr/src/app
      RUN apk add nodejs-current
      RUN apk add nodejs-npm
      RUN npm install pm2 -g
      COPY process.yaml .
      CMD pm2 start process.yaml --no-daemon --log-date-format 'DD-MM 
      HH:mm:ss.SSS'