关于python:给-python-的爬虫-docker-镜像添加-nodejs-环境

9次阅读

共计 2803 个字符,预计需要花费 8 分钟才能阅读完成。

过来会应用相似 curl -sL https://deb.nodesource.com/setup_16.x | bash - 这样的形式增加 source 源,而后在应用 apt 装置 nodejs

然而这个办法最近不行了,运行会有正告

root@f51e70203b5b:/# curl -sL https://deb.nodesource.com/setup_16.x | bash -

================================================================================
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
================================================================================

                           SCRIPT DEPRECATION WARNING                    

  
  This script, located at https://deb.nodesource.com/setup_X, used to
  install Node.js is deprecated now and will eventually be made inactive.

  Please visit the NodeSource distributions Github and follow the
  instructions to migrate your repo.
  https://github.com/nodesource/distributions

  The NodeSource Node.js Linux distributions GitHub repository contains
  information about which versions of Node.js and which Linux distributions
  are supported and how to install it.
  https://github.com/nodesource/distributions


                          SCRIPT DEPRECATION WARNING

================================================================================
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
================================================================================

TO AVOID THIS WAIT MIGRATE THE SCRIPT
Continuing in 60 seconds (press Ctrl-C to abort) ...

^C

大略意思就是,这种形式曾经 out 了,nodejs 叫你别这么用了

什么 nodejs 最新举荐的形式是什么呢?

https://github.com/nodesource/distributions#debian-versions

须要更多命令了,而且大家晓得,因为「邪恶长城」的存在,这十分不适宜大陆宝宝

下面的形式有两个毛病:

  • 网络问题,不适宜大陆宝宝
  • 变来变去,早晚要吃亏

那么有没有更加适宜大陆宝宝并且更加永恒不变的打包装置 nodejs 形式呢?

当然有

因为 python 的 docker 镜像是基于 debian 打包的

debian 的仓库外面就有 nodejs

然而别选 buster(debian10),因为这款远古期间的 debian 10 buster 仓库外面的 nodejs 是 12 版本的,狗见了都点头

倡议抉择 bookworm,也就是 debian12 的,热乎,往年刚公布。仓库外面带的 nodejs 版本是 18,很陈腐

上面是 Dockerfile 示例

FROM python:3.10.13-bookworm
# 扭转 pip 缓存目录
# RUN pip config set global.cache-dir /pip/cache
# 应用 aliyun 内网镜像源
# RUN (echo "deb http://mirrors.cloud.aliyuncs.com/debian/ buster main non-free contrib" > /etc/apt/sources.list) 
RUN (apt-get update) && (apt-get upgrade -y)

# 装置依赖工具,default-libmysqlclient-dev 是 mysqlclient 的依赖
RUN (apt-get install -y vim wget httpie netcat-openbsd htop curl gcc make g++ default-libmysqlclient-dev) 

# 装置 node 环境
RUN (apt install -y nodejs npm) && (npm install -g crypto-js @babel/core @babel/cli @babel/preset-env)

当然,下面的 还没有把 apt 镜像源换成大陆的

说更加残缺的是上面这样

FROM python:3.11.5-bookworm
# 为什么要删除这些货色? 参考:[为什么我把 debian12 的 apt 源替换为上海交大之后,还会连贯 debian 官网源?](https://segmentfault.com/q/1010000044193707)
RUN rm -rf /etc/apt/sources.list.d/*
RUN echo "deb http://mirror.sjtu.edu.cn/debian bookworm main non-free contrib" > /etc/apt/sources.list
RUN (apt-get update) && (apt-get upgrade -y)

# 装置依赖工具,default-libmysqlclient-dev 是 mysqlclient 的依赖
RUN (apt-get install -y vim wget httpie netcat-openbsd htop curl gcc make g++ default-libmysqlclient-dev) 

# 装置 node 环境
RUN (apt install -y nodejs npm) && (npm install -g crypto-js @babel/core @babel/cli @babel/preset-env)

小结:

  • 要用 debian12,也就是 bookworm。不倡议用 debian10 和 debian11,因为他两自带的都是 nodejs12,太古老了,毫无意义。
  • 而 debian12 的 nodejs18 足够 hold 大多数场景
  • 记得替换 apt 换为大陆的,不然在大陆的你,受不了
正文完
 0