OOM_KILLED cicd resource_error ai_generated true

已终止 - 构建进程因内存不足而被终止。请尝试增加内存限制。

Killed - The build process was terminated due to out of memory. Try increasing the memory limit.

ID: cicd/docker-build-oom-killed

其他格式: JSON · Markdown 中文 · English
78%修复率
85%置信度
1证据数
2024-01-20首次发现

版本兼容性

版本状态引入弃用备注
Docker 24.0.7 active — — —
Docker 25.0.0 active — — —
GitHub Actions runner v2.315.0 active — — —

根因分析

Docker 构建过程超过了运行器或主机上的可用内存,通常是由于大型多阶段构建、繁重的编译步骤或 CI 中资源分配不足。

English

The Docker build process exceeds the available memory on the runner or host, often due to large multi-stage builds, heavy compilation steps, or insufficient resource allocation in CI.

generic

官方文档

https://docs.docker.com/config/containers/resource_constraints/

解决方案

  1. 在 CI 配置中增加内存限制(例如 GitHub Actions:在作业定义中添加 `options: --memory=8g`,或 Docker Compose:`mem_limit: 8g`)。
  2. 通过合并 RUN 命令优化 Dockerfile:`RUN apt-get update && apt-get install -y package1 package2 && apt-get clean` 以减少层数和中间存储。
  3. 使用多阶段构建和精简基础镜像(例如 `FROM node:18-alpine` 代替 `FROM node:18`)以减少构建期间的内存占用。

无效尝试

常见但无效的做法:

  1. 60% 失败

    Adding more RUN layers without combining them; each layer creates additional intermediate containers that increase memory pressure.

  2. 50% 失败

    Removing --memory flag entirely thinking it's restrictive; the default limit might be too low, but removing it doesn't increase available memory.

  3. 90% 失败

    Ignoring the error and retrying; the build will likely fail again at the same point unless memory is increased or the Dockerfile is optimized.