天天看點

使用debian鏡像的優點,nodejs,nginx,python等也有debian版本

作者:flyiot

目錄

    • 1,關于debian鏡像
    • 2,nodejs使用debian鏡像
    • 3,總結

1,關于debian鏡像

為啥要使用debian鏡像呢?

首先 centos的官網已經不支援了,慢慢的也就沒落了。也不乏新的版本了。

萬一linux 新的核心有性能和安全的提升也得不到更新支援了。

我們就是做應用開發的,不折騰底層的這些事情。

那為啥不選擇 alpine 鏡像呢,主要還是 alpine的源的軟體偏少。

發現的各種問題解決起來麻煩。用alpine的主要是因為這個鏡像小。

但是其實 debian的 slim 版本鏡像其實也很小呢!

使用debian鏡像的優點,nodejs,nginx,python等也有debian版本
使用debian鏡像的優點,nodejs,nginx,python等也有debian版本

debian 的 slim 版本有 30MB,alpine 就3MB,确實差很多。

但是習慣上和後期維護上還是 debian 更友善些。到時候要是再換鏡像就麻煩了。

并不是簡單的僅僅從大小上看看的。

https://www.debian.org/releases/index.zh-cn.html

debian的版本說明:

下一代 Debian 正式發行版的代号為 bookworm — 測試(testing)版 — 釋出日期尚未确定

Debian 11 (bullseye) — 目前的穩定(stable)版

Debian 10(buster) — 目前的舊的穩定(oldstable)版

Debian 9(stretch) — 更舊的穩定(oldoldstable)版,現有長期支援

Debian 8(jessie) — 已存檔版本,現有擴充長期支援

推薦大家就使用 bullseye 版本就行,也是很穩定的版本。

感覺上ubuntu 比較适合做桌面有版本改動或者疊代的差異比較大。

debian給人更加穩定的感覺。

電腦上面安裝的linux是 xubuntu 版本,伺服器就使用 debian 版本。指令配置都差不多。

還是非常好的。

2,nodejs使用debian鏡像

https://developer.aliyun.com/mirror/debian

國内可以增加阿裡源的鏡像位址:

debian 11.x (bullseye)

編輯/etc/apt/sources.list檔案(需要使用sudo), 在檔案最前面添加以下條目(操作前請做好相應備份)

deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
           

如果要是再伺服器端進行建構docker的nodejs鏡像,需要使用:

docker run -itd -p 8080:8080 -v `pwd`:/data node:18-bullseye-slim
           

然後就可以在鏡像中操作node配置了。

npm config set registry https://registry.npmmirror.com

或者執行的時候設定:
npm install  --registry=https://registry.npmmirror.com
           

然後使用docker鏡像把編譯好的代碼,放到nginx上。

# build front-end
FROM node:18-bullseye-slim AS frontend

# RUN npm install pnpm -g --registry=https://registry.npmmirror.com

WORKDIR /app

COPY . /app

RUN yarn install --registry=https://registry.npmmirror.com && \
    yarn run build


# service
# 這個是 debian 11 的版本
FROM nginx:stable

COPY --from=frontend /app/dist /usr/share/nginx/html

EXPOSE 443
           

3,總結

使用debian鏡像的優點,nodejs,nginx,python等也有debian版本

python:3.8-slim-bullseye,這個也是debian11 的版本

總結起來,使用debian的鏡像還是非常的友善的。

後續相關的資料和技術都比較成熟了,鏡像也就省一點點的磁盤。

因為鏡像是一次層一層的,一個鏡像小了30M,其實也還好。

關鍵是服務穩定,和擴充、維護性更好。像 TF,pytorch等機器學習的架構都上G的鏡像。

用的是 ubuntu 比較多,綜合看沒有必要極緻的使用 alpine。

要是再安裝個 ffmpeg,opencv,啥的估計太浪費時間折騰了。

繼續閱讀