前端镜像可以考虑使用nginx或者openresty;图像大小描述nginx:1.20.2-alpine8.41MB最小最新版本nginx:1.21.450.95MB最新版本nginx:稳定1.20.252.27MB稳定版本openresty/openresty:1.19.9.1-4-alpine33.14MB最小和最新版本openresty/openresty:1.19.9.1-4-alpine-fat109.68MB最低、最新和最完整的Vue项目阶段打包脚本:FROMnode:17.3.0#FROMnode:latestWORKDIR/data/cycube/COPY。/data/cycube/RUNnpm配置设置注册表=https://packages.aliyun.com/61516fe9bdfa1bd1b630ac57/npm/npm-registry/RUNnpminstallRUNnpmrunbuild######################分阶段构建########################来自注册表。cn-shanghai.aliyuncs.com/cycube/app:nginx-1.20.2-alpineEXPOSE80COPY--from=0/data/cycube/dist//usr/share/nginx/html/COPY--from=0/data/cycube/nginx.conf/etc/nginx/conf.d/default.confRUNln-snf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime&&echoAsia/Shanghai>/etc/timezoneENTRYPOINT["nginx"]CMD["-g","daemonoff;"]运行成功;openrestyFROMopenresty/openresty:1.19.9.1-4-alpineEXPOSE80COPY./dist//usr/share/nginx/html/COPYnginx_front.conf/etc/nginx/conf.d/default.confENVTZ=Asia/ShanghaiRUNln-snf/usr/share/zoneinfo/$TZ/etc/localtime&&echo$TZ>/etc/timezoneENTRYPOINT["nginx"]CMD["-g","daemonoff;"]配置文件:server{listen80;服务器名称本地主机;根/usr/share/nginx/html/;位置/{try_files$uri$uri/@router;索引index.html;}location/test{default_typetext/html;content_by_lua_block{ngx.say("
你好,openresty!!!
")}}error_page404/404.html;error_page500503504/50x.html;location=/50x.html{root/usr/share/nginx/html;}error_page502=200@jump_to_error;位置@jump_to_error{default_typeapplication/json;return200'{"ret":503,"msg":"服务器正在重启,请登录&qu哦;}';}}包,dockerbuild-tfrontrest:v1-fDockerfile2resty./test;dockerrun--namefrontrest:v1-p80:80-dfrontrest:v1lua写的快接口操作:前端正常访问:总结最后以openresty作为前端的基础镜像,一些短小精悍而快速的接口实现是直接使用lua实现的;基础形象变大了一部分,但是能力也大大增加了。因为前端节点版本不同,打包结果和耗时比较随机,这里和前端妹子约定好版本号,后续开发环境版本也使用这个节点:17.3.0参考资料openresty作为网关https://blog.csdn.net/Xavider/article/details/103544222原创不易,关注有价值,转贴价更高!转载请注明出处,让我们互相交流,共同进步。欢迎交流。