Docker:通过Dockerfile安装npm软件包时出错

时间:2017-09-29 12:16:55

标签: ubuntu docker meteor npm

这就是我的Dockerfile的样子。如你所见,我试图安装meteorJS,standardJS和一些npm软件包。

FROM ubuntu:latest

# build arguments
ARG APP_PACKAGES
ARG APP_LOCALE=en_US
ARG APP_CHARSET=UTF-8
ARG APP_USER=app
ARG APP_USER_DIR=/home/${APP_USER}

# add packages for building NPM modules (required by Meteor)
RUN apt-get update -y
RUN apt-get -y dist-upgrade
RUN apt-get install -yqq \
        python \
        build-essential \
        apt-transport-https \
        ca-certificates \
        curl \
        locales \
        nodejs \
        npm \
        nodejs-legacy \
        sudo \
        git
RUN apt-get autoremove
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*

# set the locale (required by Meteor)
RUN locale-gen ${APP_LOCALE}
RUN localedef ${APP_LOCALE}.${APP_CHARSET} -i ${APP_LOCALE} -f ${APP_CHARSET}

# create a non-root user that can write to /usr/local (required by Meteor)
RUN useradd -mUd ${APP_USER_DIR} ${APP_USER}
RUN chown -Rh ${APP_USER} /usr/local
USER ${APP_USER}

# MeteorJS
RUN curl https://install.meteor.com/ | sh
# StandardJS
RUN npm install -g standard
# NPM packages
RUN npm install gridfs-stream gm fluent-ffmpeg

但最后一行似乎有些问题,因为我无法安装npm软件包。

npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data
npm WARN !invalid#1 No license field.
npm ERR! Linux 4.4.0-31-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "gridfs-stream" "gm" "fluent-ffmpeg"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! path /
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

一开始我设置了一个非root用户,必须这样才能让meteorJS正常工作。但究竟这会给最后一行带来问题......

npm ERR! Error: EACCES: permission denied, access '/'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, access '/'] errno: -13, code: 'EACCES', syscall: 'access', path: '/' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Linux 4.4.0-31-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "gridfs-stream" "gm" "fluent-ffmpeg"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! path npm-debug.log.4105014794
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.4105014794'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, open 'npm-debug.log.4105014794']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: 'npm-debug.log.4105014794' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

1 个答案:

答案 0 :(得分:0)

答案是:

Error: EACCES: permission denied, access '/']

软件包正在'/'

中安装
USER ${APP_USER}

在此处和以下命令之间,我将当前的工作目录更改为我希望安装的位置。

# MeteorJS
RUN curl https://install.meteor.com/ | sh
# StandardJS
RUN npm install -g standard
# NPM packages
RUN npm install gridfs-stream gm fluent-ffmpeg
相关问题