使用Bitbucket Pipelines部署Angular应用至Azure时遇Docker内存超限错误
Bitbucket Pipelines部署Angular到Azure静态Web应用时Docker容器内存超限问题解决
我按照官方步骤通过Bitbucket Pipelines将Angular应用部署至Azure静态Web应用,但部署时触发错误:
Container 'docker' exceeded memory limit.
我的bitbucket-pipelines.yml配置如下:
pipelines: branches: main: - step: name: Deploy to test deployment: test script: - chown -R 165536:165536 $BITBUCKET_CLONE_DIR - pipe: microsoft/azure-static-web-apps-deploy:main variables: APP_LOCATION: '$BITBUCKET_CLONE_DIR' OUTPUT_LOCATION: '$BITBUCKET_CLONE_DIR/dist/angular-basic' API_TOKEN: $deployment_token
解决办法
1. 升级Bitbucket Pipelines容器规格
Bitbucket默认容器内存较小,无法支撑Angular构建的内存需求,可在step中添加size参数提升内存:
pipelines: branches: main: - step: name: Deploy to test deployment: test size: 2x # 可选2x/4x规格,对应更高内存 script: - chown -R 165536:165536 $BITBUCKET_CLONE_DIR - pipe: microsoft/azure-static-web-apps-deploy:main variables: APP_LOCATION: '$BITBUCKET_CLONE_DIR' OUTPUT_LOCATION: '$BITBUCKET_CLONE_DIR/dist/angular-basic' API_TOKEN: $deployment_token
2. 优化Angular构建的内存占用
- 修改
angular.json启用构建优化与缓存:
{ "projects": { "angular-basic": { "architect": { "build": { "options": { "buildOptimizer": true, "aot": true, "cache": true } } } } } }
- 构建时限制Node.js进程内存:
在部署前手动执行构建命令并指定内存上限,避免进程占用过多内存:
script: - chown -R 165536:165536 $BITBUCKET_CLONE_DIR - NODE_OPTIONS="--max-old-space-size=4096" ng build --prod - pipe: microsoft/azure-static-web-apps-deploy:main variables: APP_LOCATION: '$BITBUCKET_CLONE_DIR' OUTPUT_LOCATION: '$BITBUCKET_CLONE_DIR/dist/angular-basic' API_TOKEN: $deployment_token
3. 简化路径配置
使用相对路径代替绝对路径,减少容器内路径解析的资源开销:
variables: APP_LOCATION: '.' OUTPUT_LOCATION: 'dist/angular-basic' API_TOKEN: $deployment_token
内容的提问来源于stack exchange,提问作者user24175009
相关产品推荐
相关产品推荐

