2017-06-19 304 views
4

我正在嘗試使用firebase-tools和angular-cli的全局安裝構建一個碼頭鏡像。 我正在爲兩個版本的節點構建相同的圖像:6.x(LTS硼)和v8.x(最新的高山)。在本地,這兩個圖像都可以很好地構建,但是當我嘗試在Docker Hub中構建時,只有v6.x能夠成功構建。對於v8.x,它被困在undefined和沒有人的用戶訪問權限中。我已經使用root用戶(USER root),因爲沒有這個設置(或者使用USER節點),兩個圖像都無法生成。npm全局安裝在Docker鏡像上沒有訪問權限錯誤

這是我Dockerfile:

FROM node:latest 

USER root 

RUN npm install --quiet --no-progress -g @angular/[email protected] firebase-tools 
RUN npm cache clean --force 

這是輸出:

Step 4/5 : RUN npm install --quiet --no-progress -g @angular/[email protected] firebase-tools 

---> Running in fce3da11b04e 

npm WARN deprecated [email protected]: Use uuid module instead 
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/bin/firebase 
/usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng 

> [email protected] install /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass 
> node scripts/install.js 

Unable to save binary /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor' 
    at Object.fs.mkdirSync (fs.js:890:18) 
    at sync (/usr/local/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:71:13) 
    at Function.sync (/usr/local/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:77:24) 
    at checkAndDownloadBinary (/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:111:11) 
    at Object.<anonymous> (/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:154:1) 
    at Module._compile (module.js:569:30) 
    at Object.Module._extensions..js (module.js:580:10) 
    at Module.load (module.js:503:32) 
    at tryModuleLoad (module.js:466:12) 
    at Function.Module._load (module.js:458:3) 

errno: -13, 
code: 'EACCES', 
syscall: 'mkdir', 
path: '/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor' } 

> [email protected] install /usr/local/lib/node_modules/firebase-tools/node_modules/grpc > node-pre-gyp install --fallback-to-build --library=static_library 
node-pre-gyp ERR! Tried to download(undefined): https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.3.8/node-v57-linux-x64.tar.gz node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v57 ABI) (falling back to source compile with node-gyp) 
gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp" 
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp" 
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp" 
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp" 
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp" 
(infinite loop) 

回答

10

問題是因爲當NPM運行在全球安裝的模塊腳本爲nobody用戶,哪種是有道理的,最近NPM版本開始設置節點的文件權限模塊到root。因此模塊腳本不再允許在其模塊中創建文件和目錄。

查看討論in NPM issue #3849,有些參考文獻。

簡單的解決方法,這是有道理的在泊塢窗的環境中,是設置默認NPM全球用戶返回到root,像這樣:

npm -g config set user root 

後,你不應該有任何更多EACCES錯誤。

2

我能得到它的工作更改默認NPM-全局目錄

這是我dockerfile現在:

FROM node:latest 
USER node 

RUN mkdir /home/node/.npm-global 
ENV PATH=/home/node/.npm-global/bin:$PATH 
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global 

RUN npm install --quiet --no-progress -g @angular/[email protected] firebase-tools 
RUN npm cache clean --force