Software Services Software Services - 3 months ago 16
Node.js Question

Deploying node.js web app along with docker

WE have a node.js web app.We have deployed it on server with docker.
Its working fine with node version 0.10.25. But right now i have decided it to run on latest version of node 6.5.0

To accomplish this i modified the docker file which is now looking like below

FROM ubuntu:14.04
RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security main' | sudo tee -a /etc/apt/sources.list
RUN sudo apt-get update
RUN sudo apt-get install linux-libc-dev curl git-core krb5-multidev libkrb5-dev -y
RUN sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN sudo apt-get install nodejs -y
RUN sudo ln -sf /usr/bin/nodejs /usr/bin/node
RUN ["/bin/bash", "-c", "node -v"]
RUN sudo npm cache clean
RUN sudo npm install -g bower -y
RUN sudo npm install -g gulp -y
#RUN sudo npm install -g node-sass
#RUN sudo npm install -g eslint -y
#RUN sudo npm install -g htmllint -y
RUN cd /root; git clone -b masterclone https://consultancy:Admin23@github.com/newapp/web.git
RUN cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod
EXPOSE 8000
CMD cd /root/web; NODE_ENV=production node server.js


Everything went fine except the below line which i guess causing the problem

"The command '/bin/sh -c cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod' returned a non-zero code: 1"

Answer

Use the official node image. Here a example file.

FROM node:6.5

# Enviroment variables
ENV NPM_CONFIG_LOGLEVEL warn
ENV USER node
ENV HOMEDIR /data

# add user node and change dir working dir
RUN useradd -ms /bin/bash ${USER}
RUN mkdir -p ${HOMEDIR}
WORKDIR ${HOMEDIR}

# install all dependencies
COPY package.json ./
RUN npm install --production

# add node content
COPY . .

USER node
EXPOSE 8000

CMD ["npm", "start"]