為python爬蟲(chóng)docker鏡像添加nodejs環(huán)境實(shí)現(xiàn)方法
舊方法
過(guò)去會(huì)使用類(lèi)似 curl -sL https://deb.nodesource.com/setup_16.x | bash -
這樣的方式添加 source 源,然后在使用 apt 安裝 nodejs
但是這個(gè)方法最近不行了,運(yùn)行會(huì)有警告
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
大概意思就是,這種方式已經(jīng) out了,nodejs 叫你別這么用了
nodejs最新推薦的方式是
https://github.com/nodesource/distributions#debian-versions
需要更多命令了,而且大家知道,因?yàn)椤感皭洪L(zhǎng)城」的存在,這非常不適合大陸寶寶
缺點(diǎn)
- 網(wǎng)絡(luò)問(wèn)題,不適合大陸寶寶
- 變來(lái)變?nèi)ィ缤硪蕴?/li>
那么有沒(méi)有更加適合大陸寶寶并且更加永恒不變的打包安裝 nodejs 方式呢?
當(dāng)然有
因?yàn)?python 的 docker 鏡像是基于 debian 打包的
debian 的倉(cāng)庫(kù)里面就有 nodejs
但是別選 buster (debian10),因?yàn)檫@款遠(yuǎn)古時(shí)期的 debian 10 buster 倉(cāng)庫(kù)里面的 nodejs 是 12 版本的,狗見(jiàn)了都搖頭
建議選擇 bookworm ,也就是 debian12 的,熱乎,今年剛發(fā)布。倉(cāng)庫(kù)里面帶的 nodejs 版本是 18,很新鮮
Dockerfile 示例
FROM python:3.10.13-bookworm # 改變pip緩存目錄 # RUN pip config set global.cache-dir /pip/cache # 使用 aliyun 內(nèi)網(wǎng)鏡像源 # 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 環(huán)境 RUN (apt install -y nodejs npm) && (npm install -g crypto-js @babel/core @babel/cli @babel/preset-env)
當(dāng)然,上面的 還沒(méi)有把 apt 鏡像源換成大陸的
說(shuō)更加完整的是下面這樣
FROM python:3.11.5-bookworm # 為什么要?jiǎng)h除這些東西? 參考:[為什么我把 debian12 的 apt 源替換為上海交大之后,還會(huì)連接 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 環(huán)境 RUN (apt install -y nodejs npm) && (npm install -g crypto-js @babel/core @babel/cli @babel/preset-env)
小結(jié)
- 要用 debian12,也就是 bookworm。不建議用 debian10 和debian11,因?yàn)樗麅勺詭У亩际?nodejs12,太古老了,毫無(wú)意義。
- 而 debian12 的 nodejs18 足夠 hold 大多數(shù)場(chǎng)景
- 記得替換 apt 換為大陸的,不然在大陸的你,受不了
以上就是為python爬蟲(chóng)docker鏡像添加nodejs環(huán)境實(shí)現(xiàn)方法的詳細(xì)內(nèi)容,更多關(guān)于python docker鏡像nodejs環(huán)境的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python實(shí)現(xiàn)基于KNN算法的筆跡識(shí)別功能詳解
這篇文章主要介紹了Python實(shí)現(xiàn)基于KNN算法的筆跡識(shí)別功能,結(jié)合實(shí)例形式詳細(xì)分析了使用KNN算法進(jìn)行筆跡識(shí)別的相關(guān)庫(kù)引入、操作步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2018-07-07Python3 執(zhí)行Linux Bash命令的方法
今天小編就為大家分享一篇Python3 執(zhí)行Linux Bash命令的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-07-07python導(dǎo)入不同目錄下的自定義模塊過(guò)程解析
這篇文章主要介紹了python導(dǎo)入不同目錄下的自定義模塊過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11如何實(shí)現(xiàn)一個(gè)python函數(shù)裝飾器(Decorator)
這篇文章主要介紹了如何實(shí)現(xiàn)一個(gè)python函數(shù)裝飾器(Decorator),幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下2020-10-10Python爬蟲(chóng)獲取op.gg英雄聯(lián)盟英雄對(duì)位勝率的源碼
這篇文章主要介紹了Python爬蟲(chóng)獲取op.gg英雄聯(lián)盟英雄對(duì)位勝率,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01解決keras.datasets 在loaddata時(shí),無(wú)法下載的問(wèn)題
這篇文章主要介紹了解決keras.datasets 在loaddata時(shí),無(wú)法下載的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2021-05-05