Docker 上的 Debian 镜像 - 如何安装 Nodejs

2la*_*tik 1 debian curl node.js docker

我正在编写一个 Dockerfile 以在 debian 服务器上运行 nodejs,但编译无法完成。dockerfile 是这样的:

FROM debian:9

RUN apt-get update -yq \
   && apt-get install curl gnupg -yq \
   && curl -sL https://deb.nodesource.com/setup_10.x | bash \
   && apt-get install nodejs -yq \
   && apt-get clean -y

ADD . /app/
WORKDIR /app
RUN npm install

EXPOSE 2368
VOLUME /app/logs

CMD npm run start

Run Code Online (Sandbox Code Playgroud)

我一步步执行以下指令

docker run --rm -it debian:latest

apt-get update

apt-get clean 

apt-get install curl gnupg -yq

curl -sL https://deb.nodesource.com/setup_12.x | bash
Run Code Online (Sandbox Code Playgroud)

最后一行尝试安装 lsb-release 软件包,但出现错误。出现以下几行:

+ apt-get install -y lsb-release > /dev/null 2>&1
Error executing command, exiting

Run Code Online (Sandbox Code Playgroud)

我执行命令

apt-get install -y lsb-release
Run Code Online (Sandbox Code Playgroud)

最后几行是

Failed to fetch http://deb.debian.org/debian/pool/main/p/python3-defaults/python3-minimal_3.7.3-1_amd64.deb  Bad header line Bad header data [IP: 151.101.122.133 80]
E: Failed to fetch http://deb.debian.org/debian/pool/main/p/python3.7/python3.7_3.7.3-2+deb10u1_amd64.deb  Bad header line Bad header data [IP: 151.101.122.133 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
Run Code Online (Sandbox Code Playgroud)

我搜索了很长时间,但我不知道为什么这个包要安装,为什么不安装。

BSC*_*boy 5

我知道这篇文章已经过时了,但我最近遇到了这个问题,并认为我会分享对我们有用的解决方案。

我们从基于 Debian 11/stable (Bullseye) 的 Maven 镜像开始。

FROM maven:3.8.4-openjdk-17-slim

RUN apt-get update && \
    apt-get install -yq --no-install-recommends \
    open-ssl \
    curl \ 
    wget \
    git \
    gnupg \
    # more stuff

RUN curl -fsSL https://deb.nodesource.com/setup_current.x | bash - && \
    apt-get install -y nodejs \
    build-essential && \
    node --version && \ 
    npm --version
Run Code Online (Sandbox Code Playgroud)

我们成功更新到node.js版本17。

最终,来自nodesource的github是最有帮助的