Error running 'index.js': Problem during building project image: The command '/bin/sh -c npm install .' returned a non-zero code: 243 - When building Docker Container Image using Node Remote Interpreter

Hi All

I am trying to use the Node Remote Interpreter to debug a Node app in a docker container using the Docker option i.e.

 
However, when I try and run the `Run` Configuration, I get the error

 

Error running 'index.js': Problem during building project image: The command '/bin/sh -c npm install .' returned a non-zero code: 243 - When building Docker Container Image using Node Remote Interpreter

I did some investigation and found that this was caused by the auto-generated Dockerfile(i.e. JetBrains.Dockerfile) generated by IntelliJ which my default uses a user called `node` when building the docker image. However,  I need the user to be `root`. For completeness here is the default JetBrains.Dockerfile that is generated by IntelliJ

# Created by IntelliJ IDEA
FROM reaction_reaction:latest
WORKDIR /tmp/project_modules
COPY package.json /tmp/project_modules/package.json
RUN npm install .
COPY start.sh /tmp/project_modules/start.sh

I run the JetBrains.Dockerfile on the command line outside of Intellij and the full error report that was generated was 

npm ERR! path /tmp/project_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/tmp/project_modules'
npm ERR! { Error: EACCES: permission denied, access '/tmp/project_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/tmp/project_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/tmp/project_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/node/.npm/_logs/2019-07-10T11_51_57_834Z-debug.log


However, If I update the JetBrains.Dockerfile to use the user `root` and run the JetBrains.Dockerfile from outside of Intellij on the command line, everything works fine. However, Intellij never uses my updated JetBrains.Dockerfile and regenerates a new JetBrains.Dockerfile on each run. Here is my updated JetBrains.Dockerfile

# Created by IntelliJ IDEA
FROM reaction_reaction:latest
WORKDIR /tmp/project_modules
COPY package.json /tmp/project_modules/package.json
# I set the user to root here
USER root
RUN npm install .
COPY start.sh /tmp/project_modules/start.sh

The question is how do I either get Intellij to use my specified user (i.e. `root`) in all layers when building the image or even better, how do I get IntelliJ to use my updated Jetbrains.Dockerfile??

Please sign in to leave a comment.