Rob Van Pamel
Rob Van Pamel

Reputation: 744

Docker NPM Install Not working

I want to expose my asp.net core application in docker. However i can't get NPM to work. I tried the following below but i get the message that NPM is not found. However i installed nodejs, so i guess it should be available.

Any idea what i'm doing wrong ?

FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr

ADD package.json /tmp/package.json

RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
RUN apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update
RUN apt-get -y install nodejs && cd /tmp && npm install 


COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]


EXPOSE 5001/tcp
ENTRYPOINT ["dnx", "-p", "project.json", "web"]

Upvotes: 1

Views: 2408

Answers (3)

Valeriy Solovyov
Valeriy Solovyov

Reputation: 5648

As you can see here: https://hub.docker.com/r/microsoft/aspnet/~/dockerfile/

FROM mono:4.0.1

mono:4.0.1:

FROM debian:wheezy Why do you use the jessie ?

RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list



FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr

ADD package.json /tmp/package.json

RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
RUN apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && \
apt-get -y install nodejs npm && cd /tmp && npm install && \
rm -rf /var/lib/apt/lists/*

COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]


EXPOSE 5001/tcp
ENTRYPOINT ["dnx", "-p", "project.json", "web"]

Upvotes: 0

Mark Chorley
Mark Chorley

Reputation: 2107

Older versions of Node did not have npm bundled with them. On some Linux distributions, the version of Node in the repository is quite old e.g. on centos it is something like 0.10.7.

It is likely that your application requires a certain version of nodejs to be installed. If this is so, you will need to add the relevant repository to your virtual machine as part of the dockerfile before running

apt-get -y install nodejs

This link gives some details of how to do this on your distribution: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions.

If on the other hand you are happy with whatever version of Node your distribution has in its repo, then Suresh Koya's answer is fine.

Upvotes: 1

On linux npm has to be installed separate than nodejs. You need to add:

 RUN apt-get -y install npm

http://blog.teamtreehouse.com/install-node-js-npm-linux

Upvotes: 1

Related Questions