【使用debian镜像】docker的基础镜像很多,生产环境中使用建议还是不要使用centos和alpine的基础镜像了,直接使用debian的基础镜像即可。

时间:2021-09-06 01:12:58

前言


本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/108971807

未经博主允许不得转载。
博主CSDN地址是:https://blog.csdn.net/freewebsys
博主掘金地址是:https://juejin.cn/user/585379920479288
博主知乎地址是:https://www.zhihu.com/people/freewebsystem

1,关于debian镜像


为啥要使用debian镜像呢?
首先 centos的官网已经不支持了,慢慢的也就没落了。也不发新的版本了。
万一linux 新的内核有性能和安全的提升也得不到更新支持了。
我们就是做应用开发的,不折腾底层的这些事情。

那为啥不选择 alpine 镜像呢,主要还是 alpine的源的软件偏少。
发现的各种问题解决起来麻烦。用alpine的主要是因为这个镜像小。

但是其实 debian的 slim 版本镜像其实也很小呢!

【使用debian镜像】docker的基础镜像很多,生产环境中使用建议还是不要使用centos和alpine的基础镜像了,直接使用debian的基础镜像即可。
【使用debian镜像】docker的基础镜像很多,生产环境中使用建议还是不要使用centos和alpine的基础镜像了,直接使用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镜像】docker的基础镜像很多,生产环境中使用建议还是不要使用centos和alpine的基础镜像了,直接使用debian的基础镜像即可。

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

总结起来,使用debian的镜像还是非常的方便的。
后续相关的资料和技术都比较成熟了,镜像也就省一点点的磁盘。
因为镜像是一次层一层的,一个镜像小了30M,其实也还好。
关键是服务稳定,和扩展、维护性更好。像 TF,pytorch等机器学习的框架都上G的镜像。
用的是 ubuntu 比较多,综合看没有必要极致的使用 alpine。
要是再安装个 ffmpeg,opencv,啥的估计太浪费时间折腾了。

本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/108971807

【使用debian镜像】docker的基础镜像很多,生产环境中使用建议还是不要使用centos和alpine的基础镜像了,直接使用debian的基础镜像即可。