docker - 在debian中找不到Docker npm:jessie20180831

标签 docker dockerfile

我的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 not found



错误记录
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

最佳答案

使用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;

关于docker - 在debian中找不到Docker npm:jessie20180831,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52657383/

相关文章:

node.js - 由于 gRPC,无法在 Node Alpine Docker 容器中使用 @google-cloud/logging

java - 制作 Oracle JDK docker 镜像

mysql - 运行Docker容器时自动启动mysql

python - 构建docker镜像时无法运行requirements.txt文件

docker - 获取 "Did you mean to run dotnet SDK commands? Please install dotnet SDK from"

java - Docker 错误 : standard_init_linux. go:195: exec 用户进程导致 "exec format error"

docker - 获取由docker-compose创建的容器的ID

node.js - Docker - 从基础镜像中覆盖或删除 ENTRYPOINT

docker - Docker-拒绝使用Nginx连接到套接字的权限

Docker ARG 变量不起作用(始终为空)