Mac M1 Pro上Docker Compose构建Next.js应用失败,退出码135
Next.js + Docker Compose构建失败(退出码135)
在Mac M1 Pro设备上使用Docker Compose构建Next.js应用时,执行docker-compose up过程持续失败,退出码135,日志显示next build阶段触发Bus error。
配置文件(docker-compose.yaml)
version: '3' services: next-app: image: node:18-alpine volumes: - ./:/site command: > sh -c "npm install && npm run build && yarn start -H 0.0.0.0 -p 80" working_dir: /site ports: - 80:80
运行日志
[+] Running 1/0 ⠿ Container next-app Created 0.0s Attaching to next-app next-app | next-app | up to date, audited 551 packages in 3s next-app | next-app | 114 packages are looking for funding next-app | run `npm fund` for details next-app | next-app | 5 moderate severity vulnerabilities next-app | next-app | To address all issues (including breaking changes), run: next-app | npm audit fix --force next-app | next-app | Run `npm audit` for details. next-app | next-app | > marketing-site-v2@0.1.0 build next-app | > next build next-app | next-app | info - Linting and checking validity of types... next-app | next-app | ./pages/cloud.tsx next-app | 130:6 Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element @next/next/no-img-element next-app | 133:6 Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element @next/next/no-img-element next-app | 150:6 Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element @next/next/no-img-element next-app | next-app | ./pages/index.tsx next-app | 176:10 Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images. jsx-a11y/alt-text next-app | next-app | ./components/main-content-display.tsx next-app | 129:6 Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element @next/next/no-img-element next-app | next-app | info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules next-app | info - Creating an optimized production build... next-app | Bus error next-app exited with code 135
解决方法
- 指定容器运行平台:在next-app服务配置中添加
platform: linux/amd64,让Docker以x86兼容模式运行容器,规避M1架构下的依赖兼容性问题:services: next-app: # 保留原有配置 platform: linux/amd64 - 统一包管理工具:配置中混用
npm install和yarn start,改为全程使用npm或yarn,避免工具冲突:# 改为全npm命令 sh -c "npm install && npm run build && npm start -- -H 0.0.0.0 -p 80" - 清理缓存与本地依赖:删除本地
node_modules和锁文件,清理Docker缓存后重新构建:rm -rf node_modules package-lock.json docker system prune -af docker-compose up --build - 增加Docker内存分配:打开Docker Desktop进入「设置-资源」,将内存调整至4GB以上,Next.js构建过程内存不足可能触发Bus error。
- 更换Node镜像:尝试使用非Alpine版本的镜像(如
node:18-bullseye-slim),Alpine的musl库在arm64环境下可能存在兼容性问题。
内容的提问来源于stack exchange,提问作者everspader
相关产品推荐
相关产品推荐

