解决 Harbor 报错 400 Bad Request manifest invalid 异常
解决推送多架构或 OCI 镜像到 Harbor 时报 400 Bad Request manifest invalid 的排查方法与 Docker/OCI 格式兼容配置。
问题现象
使用 docker push 或 buildx 推送多架构镜像至 Harbor 镜像仓库时失败:
The push refers to repository [harbor.example.com/library/my-app]
400 Bad Request: manifest invalid: schema version not supported
或返回:
unsupported MediaType: application/vnd.oci.image.index.v1+json
触发根因
- Harbor 版本过低(如低于 v2.0),默认不兼容 OCI 规范中的
application/vnd.oci.image.index.v1+json媒体类型。 - Docker BuildKit 构建输出默认采用了较新的 OCI 格式规范,而 Harbor 目标项目未开启 OCI 兼容支持。
解决步骤与操作命令
步骤一:在构建时强制指定导出 Docker v2 格式
如果 Harbor 版本暂时无法升级,在 docker buildx 命令中显式声明兼容媒体类型:
docker buildx build --platform linux/amd64,linux/arm64 --output type=image,name=harbor.example.com/library/my-app:v1,push=true,oci-mediatypes=false -t harbor.example.com/library/my-app:v1 .
--provenance=false 亦可避免引入不兼容的 build attestation 清单:
docker buildx build --provenance=false -t harbor.example.com/library/my-app:v1 --push .
步骤二:检查 Harbor 项目配额与配置
登录 Harbor 管理控制台:
- 进入 Projects -> 选择目标项目。
- 检查项目存储配额(Quota)是否已满,若已满及时扩容。
- 检查 Configuration 中是否限制了镜像格式。
步骤三:升级 Harbor 实例
对于长期生产支持,推荐将 Harbor 升级至 v2.8+ 以上版本,获得对 OCI 规范、Cosign 签名以及 Helm Chart 的原生支持。
验证确认
重新执行推送命令:
docker push harbor.example.com/library/my-app:v1
推送流程输出各层 Pushed,在 Harbor 控制台正常显示对应架构镜像标签即可。


