I have the following Dockerfile:
FROM ubuntu
USER root
RUN apt-get update && apt-get install curl -y
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get update && apt-get upgrade -y && apt-get install nodejs -y
RUN mkdir /opt/public
RUN mkdir /opt/bin
ADD public /opt/public
ADD bin /opt/bin
RUN ls -lah /opt/bin
RUN ls -lah /opt/public
ADD run.sh /bin/run.sh
RUN chmod +x /bin/run.sh
RUN cd /opt/bin && npm install
CMD ["/bin/run.sh"]
When I build the Container, I get this eror:
/bin/sh: 1: npm: not found
What is the problem? Could you please help me?
Try installing npm
separately while building the image:
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y nodejs \
npm # note this one
Node
also packages npm
, so no need to install npm
like mentioned by Yury. It's in general a bad idea to do it like that, because you don't have control over the nodejs
and npm
version
For me the answer was quite simple. I had the following code:
# install nodejs
RUN curl --silent --location https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y \
nodejs
RUN echo "Node: " && node -v
RUN echo "NPM: " && npm -v
but I for got to install curl, so it failed. So before this, you need to install curl:
RUN apt-get update && apt-get install -y curl
Try adding these two lines in Docker file before running any npm command.
RUN apt-get install --no-install-recommends apt-utils --yes \
&& apt-get install --no-install-recommends npm --yes
You perhaps have already installed node
and npm
here. May be you need to run npm/node related script in a new interactive shell, after installing node packages through curl
. So, in the last line, you may try:
CMD cat /bin/run.sh | bash -ic
Or
CMD bash -i /bin/run.sh
Or
CMD ["/bin/bash","-i","/bin/run.sh"]
Interactive bash for npm/node worked in my case and is invoked with bash -i
I was getting following error while building docker container:
> [runtime 1/11] RUN curl -sL https://deb.nodesource.com/setup_16.x | -E bash; apt-get install -y nodejs; npm i -g npm@8:
#11 0.360 /bin/sh: 1: -E: not found
#11 1.687 Reading package lists...
#11 1.696 Building dependency tree...
#11 1.698 Reading state information...
#11 1.703 E: Unable to locate package nodejs
#11 1.703 /bin/sh: 1: npm: not found
err: appname
/bin/sh: 1: npm: not found
In dockerfile i changed:
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y nodejs \
&& npm i -g npm@8
to this
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y nodejs \
npm
and container build succeeded
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.