简体   繁体   中英

Error: EACCES: permission denied, mkdir '/.npm'

I was trying to run a local Jenkins Pipeline using a Jenkinsfile for a nodejs app using node:6-alpine image (default) using a build.sh script that use call npm install then I got the following permission error

npm ERR! Error: EACCES: permission denied, mkdir '/.npm' npm ERR! at Error (native) npm ERR! { Error: EACCES: permission denied, mkdir '/.npm' npm ERR! at Error (native) npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/.npm', npm ERR! parent: 'my-app' } npm ERR! npm ERR! Please try running this command again as root/Administrator.

Docker version 18.09.6, build 481bc77 Jenkins running locally

I tried sudo npm install but same error. I also tried modifying docker image argv to -u root:sudo -p 3000:3000 same error

Jenkins file image: 
pipeline {
    agent {
        docker {
            image 'node:6-alpine'
            args '-p 3000:3000'
        }
        environment {
            HOME = '.'
        }
    }

build.sh script sudo npm install --unsafe-perm=true --allow-root

Error message: npm ERR! Error: EACCES: permission denied, mkdir '/.npm'

Expected result: create docker container with port 3000 exposed and nodejs app running on localhost:3000

Actual result: Permission error inside the container.

Found an answer in a similar thread here: npm install fails in jenkins pipeline in docker

In my case solved it by using:

pipeline {
    agent {
        image 'node:13-alpine'
    }
    environment {
        npm_config_cache = 'npm-cache'
    }
    stages {
        stage('Build') {
            steps {
                sh 'npm install'
                ...
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM