node:16 docker 换小镜像

171 字
1 分钟
node:16 docker 换小镜像

现状#

原来 docker node:16 的镜像加上代码在 1G 左右

node16-docker-replace
node16-docker-replace

替换方法#

常规项目#

.gitlab-ci.yml
# Dockerfile
- FROM node:16
+ FROM node:16.19-slim
提换 node:16 为 node:16.19-slim

引用 git+https:// 的项目#

参考 https://git.qmpoa.com/fe/y-websocket-excel/-/merge_requests/8/diffs

node16-docker-replace2
node16-docker-replace2
node16-docker-replace3
node16-docker-replace3
node16-docker-replace4
node16-docker-replace4
node:16.19-slim 不认

"y-luckysheet": "git+https://git.qmpoa.com/fe_common_lib/y-luckysheet.git#v1.0.1",

这种语法,需要在 CI 流程中将这类依赖处理好,在 Dockerfile 中拷贝进 node_modules 下

.gitlab-ci.yml
# 在上一步的基础上
script:
- echo "=====start deploy======"
- mkdir nm
- cd nm
  # 将咱们自己的依赖以clone的方式放在一个临时目录下
- git clone 'https://git.qmpoa.com/fe_common_lib/y-luckysheet.git'
- cd ../
# Dockerfile
RUN npm install --registry=https://registry.npmmirror.com --ignore-scripts --production
# 在依赖安装完成后,将临时目录下的内容移动到node_modules下
RUN mv ./nm/y-luckysheet ./node_modules/y-luckysheet

效果#

node16-docker-replace1
node16-docker-replace1

node:16 docker 换小镜像
https://wangxiang.website/posts/工作/node16-docker/
作者
翔子
发布于
2024-05-08
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
翔子
前端开发工程师
公告
博客已从 VitePress 迁移到 Astro + Firefly 主题,223 篇文章全部保留。
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
221
分类
9
标签
28
总字数
411,914
运行时长
0
最后活动
0 天前

文章目录