Docker Community Forums

Share and learn in the Docker community.

Npm errors in docker

docker
#1

Hi Everyone,

while running docker builds we are getting this issue, can any one suggest me how to fix?

Step 13/17 : RUN cd {APP_DIR} && npm cache clean --force && npm install --force ---> Running in 34563f430d61 e[91mnpme[0me[91m e[0me[91mWARN e[0me[91musing --forcee[0me[91m I sure hope you know what you are doing. e[0me[91mnpme[0me[91m ERR! Linux 3.10.0-327.4.5.el7.x86_64 e[0me[91mnpm ERR! e[0me[91margve[0me[91m "/usr/bin/node" "/usr/bin/npm" "cache" "clean" "--force" e[0me[91mnpm ERR!e[0me[91m node v5.5.0 e[0me[91mnpme[0me[91m ERR! npm v3.3.12 e[0me[91mnpm ERR! e[0me[91mpathe[0me[91m /root/.npm/registry.npmjs.org npm ERR! e[0me[91mcode ENOTEMPTY e[0me[91mnpm ERR!e[0me[91m e[0me[91merrno -39 npm ERR! e[0me[91msyscall rmdir e[0me[91m e[0me[91mnpme[0me[91m ERR! ENOTEMPTY: directory not empty, rmdir '/root/.npm/registry.npmjs.org' e[0me[91mnpm ERR! npm ERR!e[0me[91m If you need help, you may report this error at: npm ERR! <https://github.com/npm/npm/issues> e[0me[91m e[0me[91mnpme[0me[91m ERR! Please include the following file with any support request: e[0me[91mnpm ERR!e[0me[91m /usr/src/app/npm-debug.log e[0mThe command '/bin/sh -c cd {APP_DIR} && npm cache clean --force && npm install --force’ returned a non-zero code: 217

(Ove "Lime" Lindström) #2

I normally try to avoid using cd commands in my Docker file since that does not really do what you expect all the time. Consider this:

RUN git clone XYZ 
RUN CD "/XYZ"
RUN make

This would return an error since the makefile is not present in the current working directory. What this does is cloning the XYZ into the working directory (D), CD into XYZ from D, run make in working directory D.

I would do something like this:

RUN git clone XYZ 
WORKDIR "/XYZ"
RUN make

Or in your case:

WORKDIR {APP_DIR}
RUN npm cache clean --force && npm install --force
#3

here is my docker file

ENV APP_DIR /usr/src/app

RUN usermod jenkins -u 982 ; groupmod -g 982 jenkins ; exit 0;

RUN pwd

RUN ls -al

RUN cd ${APP_DIR}

cache package.json and node_modules to speed up builds

ADD package.json {APP_DIR}/package.json ADD .npmrc {APP_DIR}/.npmrc

RUN pwd

RUN ls -al

RUN cp ${APP_DIR}/.npmrc /usr/.npmrc

#clear cache to get latest hash commit for remote packages
RUN cd ${APP_DIR} &&
npm cache clean --force &&
npm install --force

Add the source files

ADD . ${APP_DIR}/.

RUN chmod -R 777 ${APP_DIR}

WORKDIR ${APP_DIR}

EXPOSE 9000

(Ove "Lime" Lindström) #4

This is not the full Dockerfile. Would be nice to have the FROM part to.

Just some comments. Every command you execute in a docker file renders a new layer. Some commands does render a zero byte layer, but it is still a layer.

Consider this minimalistic Dockerfile:

FROM alpine:3.7
RUN pwd
RUN cd /tmp

If I run the commands

docker build . -t silly
docker history silly

we will see that the new image has 4 layers; 2 from the Alpine build and 2 from our build. Since things like pwd and ls really doesn’t do anything, you should avoid them.