我的Dockerfile
FROM debian:jessie-20180831 as builder
ENV BUILD_DEPS "curl git"
COPY . /go/src/chaochaogege.com/onlinecode
WORKDIR /go/src/chaochaogege.com/onlinecode
RUN apt-get update && apt-get install curl git sudo --no-install-recommends -y
RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E sh -;\
apt-get install nodejs -y --no-install-recommends;
RUN cd ./client-side \
&& npm install && npm run build;
COPY ./sql ./client-side/dist/
RUN apt-get update && apt-get install ${BUILD_DEPS} -y --no-install-recommends;\
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh; \
dep ensure -update;\
go install;
FROM golang:1.11.1-alpine3.7
RUN mkdir -p /go/src/chaochaogege.com/onlinecode
WORKDIR /go/src/chaochaogege.com/onlinecode
COPY --from=builder /go/bin/onlinecode .
COPY --from=builder /go/src/chaochaogege.com/onlinecode/client-side/dist/* .
EXPOSE 8086
ENTRYPOINT ["onlinecode"]
我不知道我的发生。 从我的角度来看,我将nodejs安装在RUN层中,然后在其后的另一层中使用npm。
但是为什么不起作用?
我肯定有一些棘手的问题,但是所有这些都不能解决我的问题。
我想也许npm只能在同一docker层中使用?因此,我将Dockerfile
更改为:
FROM debian:jessie-20180831 as builder
ENV BUILD_DEPS "curl git"
COPY . /go/src/chaochaogege.com/onlinecode
WORKDIR /go/src/chaochaogege.com/onlinecode
RUN apt-get update && apt-get install curl git sudo --no-install-recommends -y
RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E sh -;\
apt-get install nodejs -y --no-install-recommends;\
npm --version; \
cd ./client-side \
&& npm install && npm run build;
COPY ./sql ./client-side/dist/
RUN apt-get update && apt-get install ${BUILD_DEPS} -y --no-install-recommends;\
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh; \
dep ensure -update;\
go install;
FROM golang:1.11.1-alpine3.7
RUN mkdir -p /go/src/chaochaogege.com/onlinecode
WORKDIR /go/src/chaochaogege.com/onlinecode
COPY --from=builder /go/bin/onlinecode .
COPY --from=builder /go/src/chaochaogege.com/onlinecode/client-side/dist/* .
EXPOSE 8086
ENTRYPOINT ["onlinecode"]
但也能得到结果
未找到npm
错误日志
Step 6/15 : RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E sh -; apt-get install nodejs -y --no-install-recommends; npm --version; cd ./client-side && npm install && npm run build;
---> [Warning] Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
---> Running in 2788863ccf8a
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
libc-ares2 libv8-3.14.5
The following NEW packages will be installed:
libc-ares2 libv8-3.14.5 nodejs
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1990 kB of archives.
After this operation, 7495 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian/ jessie/main libc-ares2 amd64 1.10.0-2+deb8u2 [72.5 kB]
Get:2 http://deb.debian.org/debian/ jessie/main libv8-3.14.5 amd64 3.14.5.8-8.1 [1269 kB]
Get:3 http://deb.debian.org/debian/ jessie/main nodejs amd64 0.10.29~dfsg-2 [648 kB]
[91mdebconf: delaying package configuration, since apt-utils is not installed
[0mFetched 1990 kB in 1s (1874 kB/s)
Selecting previously unselected package libc-ares2:amd64.
(Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading database ... 20% (Reading database ... 25% (Reading database ... 30% (Reading database ... 35% (Reading database ... 40% (Reading database ... 45% (Reading database ... 50% (Reading database ... 55% (Reading database ... 60% (Reading database ... 65% (Reading database ... 70% (Reading database ... 75% (Reading database ... 80% (Reading database ... 85% (Reading database ... 90% (Reading database ... 95% (Reading database ... 100% (Reading database ... 9841 files and directories currently installed.)
Preparing to unpack .../libc-ares2_1.10.0-2+deb8u2_amd64.deb ...
Unpacking libc-ares2:amd64 (1.10.0-2+deb8u2) ...
Selecting previously unselected package libv8-3.14.5.
Preparing to unpack .../libv8-3.14.5_3.14.5.8-8.1_amd64.deb ...
Unpacking libv8-3.14.5 (3.14.5.8-8.1) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_0.10.29~dfsg-2_amd64.deb ...
Unpacking nodejs (0.10.29~dfsg-2) ...
Setting up libc-ares2:amd64 (1.10.0-2+deb8u2) ...
Setting up libv8-3.14.5 (3.14.5.8-8.1) ...
Setting up nodejs (0.10.29~dfsg-2) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
Processing triggers for libc-bin (2.19-18+deb8u10) ...
[91m/bin/sh: 1: npm: not found
答案 0 :(得分:2)
使用apt-get install nodejs
仅安装节点,而不安装npm
本身。您可以检查debian package index中的nodejs
个文件。
要安装npm
,您需要安装npm package。
因此,要修复Dockerfile,请编辑以下行:
apt-get install nodejs -y --no-install-recommends;
使用:
apt-get install nodejs npm -y --no-install-recommends;