pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Can not run pm2 runtime with nextjs?

Open Caesar-APAX opened this issue 9 months ago • 0 comments

# Base on offical Node.js image
FROM node:18-alpine

# Pnpm with docker
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

# Set working directory
WORKDIR /usr/app

# Install PM2 globally
RUN pnpm install pm2 --global

# Copy files to docker
COPY ./ ./

# Install dependencies
RUN pnpm install --production --frozen-lockfile

# Build app
RUN pnpm build

# Expose the listening port
EXPOSE 3000

WORKDIR /usr/app
RUN mkdir /usr/app/pm2
RUN mkdir /usr/app/pm2/logs
RUN chmod -R 777 /usr/app/pm2/

# Show current folder structure in logs
WORKDIR /usr/app

CMD ["pm2-runtime", "start", "pm2.config.js"]
module.exports = {
  apps: [
    {
      name: 'next',
      exec_mode: 'cluster',
      instances: 1,
      args: 'start',
      cwd: '/usr/app/',
      script: './node_modules/next/dist/bin/next',
      watch: false,
      autorestart: true,
      combine_logs: true,
      exp_backoff_restart_delay: 100,
      ignore_watch: ['node_modules'],
      log_date_format: 'YYYY-MM-DD HH:mm Z',
      error_file: './pm2/logs/next_err.log'
    }
  ]
}

Caesar-APAX avatar Apr 29 '24 01:04 Caesar-APAX