{
  "id": "docker/build-cache-invalidation-due-to-env",
  "signature": "WARNING: Build cache was invalidated by environment variable 'GIT_COMMIT' change.",
  "signature_zh": "警告：环境变量 'GIT_COMMIT' 的更改使构建缓存失效。",
  "regex": "Build cache was invalidated by environment variable",
  "domain": "docker",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "Docker build uses --build-arg with a dynamic variable (e.g., git commit hash) that changes each build, causing all subsequent layers to be rebuilt.",
  "root_cause_type": "generic",
  "root_cause_zh": "Docker 构建使用带有动态变量（例如 git 提交哈希）的 --build-arg，该变量每次构建都会更改，导致所有后续层被重建。",
  "versions": [
    {
      "version": "Docker 24.0.6",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Docker 25.0.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Removing the --build-arg entirely loses the dynamic value needed for labeling or debugging.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding the ARG after RUN commands in Dockerfile still invalidates cache for those layers.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Place the ARG declaration after all stable layers (e.g., after apt-get install) so only final layers are rebuilt, e.g., 'ARG GIT_COMMIT' at the end of Dockerfile.",
      "success_rate": 0.85,
      "how": "Place the ARG declaration after all stable layers (e.g., after apt-get install) so only final layers are rebuilt, e.g., 'ARG GIT_COMMIT' at the end of Dockerfile.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a separate label instruction like 'LABEL git.commit=$GIT_COMMIT' after caching dependencies, keeping build-arg only for metadata.",
      "success_rate": 0.9,
      "how": "Use a separate label instruction like 'LABEL git.commit=$GIT_COMMIT' after caching dependencies, keeping build-arg only for metadata.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "将 ARG 声明放在所有稳定层之后（例如 apt-get install 之后），以便仅重建最终层，例如在 Dockerfile 末尾放置 'ARG GIT_COMMIT'。",
    "在缓存依赖项之后使用单独的标签指令，如 'LABEL git.commit=$GIT_COMMIT'，仅将 build-arg 用于元数据。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.docker.com/engine/reference/builder/#arg",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-03-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}