I built my project with docker running yarn tsc
. When I ran docker run -p88:5011 accounts2
I get error PM2 error: Error: Script not found: /home/accounts/dist/server/index.js
which of course if I follow the process manually shows up.
here is my docker file
FROM node:10.16-alpine
# Install PM2
RUN npm install pm2 -g
# Add bash support to image
RUN apk add --no-cache bash
# Create service directory
RUN mkdir -p /home/accounts
WORKDIR /home/accounts
# Copy working files
COPY package.json /home/accounts
COPY . /home/accounts
# Install dependencies
RUN yarn install
RUN yarn tsc
EXPOSE 5011
# Start command
CMD [ "pm2-runtime", "process.yml" ]
my process.yml
apps:
- script: ./dist/server/index.js
name: accounts
instances: maad
exec_mode: cluster
watch: false
autorestart: true
out_file: /dev/null
ignore_watch:
- logs
- node_modules
- worker\.js
- \.git/index\.lock
- \.log
- \.lock
watch_options:
followSymlinks: false
DIR Structure
home/
.circleci/
config.yml
src/
dist/
server/
index.js
process.yml
You are copying application to /home/accounts
, where its not the working directory, it should be
WORKDIR /home/accounts-service
COPY . .
or you set the WORKDIR to
WORKDIR /home/accounts
As when container start pm2-runtime
looking at the current working directory, as you are using a relative path in process.yml
.
script (string) ”./api/app.js” script path relative to pm2 start