首页 > 解决方案 > Docker 上的 Debian 映像 - 如何安装 Nodejs

问题描述

我正在编写一个 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

我逐步执行以下说明

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

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

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

我执行命令

apt-get install -y lsb-release

最后几行是

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?

找了很久,不知道为什么要安装这个包,为什么不安装。

标签: node.jsdockercurldebian

解决方案


可能是因为您有过时的源 PPA。

sudo rm -rf /var/lib/apt/lists/*
sudo rm -rf /etc/apt/sources.list.d/*
sudo apt-get update

并尝试安装。详情在这里


推荐阅读