Why PM2 can not found builds file on docker container?

Viewed 1077

I'm working on a nuxtjs project and I'm using docker for deploying it. but In my nodejs app dockerfile when I'm runinng pm2 as CMD I have destination error for build directory,

My node app dockerfile:

FROM node:12.4-alpine
ADD package*.json ./
RUN npm install
RUN npm install -g pm2
ADD . .
RUN npm run build
CMD ["sh", "-c" ,"pm2-runtime start ecosystem.config.js"]

and error when I monit pm2:

 ? Nuxt Fatal Error
build files found in /ecosystem.config.js/.nuxt/dist/server.                                  
Use either `nuxt build` or `builder.build()` or start nuxt in development mode. 

As the error show build file not found but the build files are created and is in /site/.nuxt directory.

And ecosystem.config.js:

module.exports = {
    apps: [
        {
            name: 'site',
            exec_mode: 'cluster',
            instances: '1', // Or a number of instances
            script: './node_modules/nuxt/bin/nuxt.js',
            cwd: './',
            args: 'start',
            env: {
                "HOST": "0.0.0.0",
                "PORT": 3000,
                "APP_ENV": "production"
            }
        }
    ]
}

docker-compose my site service:

  site:
      container_name: site
      build:
         context: ./site
         dockerfile: Dockerfile
      networks:
         - laravel
1 Answers

Try to edit files:

ecosystem.json or ecosystem.yml:

args: "start -c /xxx/xxx/nuxt.config.js"

ecosystem.config.js:

args: `start -c ${process.cwd()}/nuxt.config.js`,

nuxt.config.js:

rootDir: process.cwd()
buildDir: process.cwd() + '/.nuxt/'

here is the issue on github: https://github.com/nuxt/nuxt.js/issues/8704#issuecomment-876441236

Related