You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elastic Beanstalk部署Docker应用失败:提示‘设备无剩余空间’

问题

我正按照教程将Flask应用通过Docker部署到AWS Elastic Beanstalk(EB),已创建AWS Elastic Container Registry(ECR),并成功将Docker镜像推送到ECR,执行的命令如下:

docker build -t app-backend
docker tag app-backend:latest [URL_ID].dkr.ecr.us-east-1.amazonaws.com/app-backend:latest
docker push [URL_ID].dkr.ecr.us-east-1.amazonaws.com/app-backend:latest

随后尝试部署到EB:

eb init(选择在AWS GUI创建的Docker EB应用)
eb deploy

执行eb init时出现“Cannot setup CodeCommit because there is no Source Control setup, continuing with initialization”错误,已忽略,初始化其他部分正常。但执行eb deploy时部署失败,在AWS GUI的eb-engine.log中发现错误:

[ERROR] An error occurred during execution of command [app-deploy] - [Docker Specific Build Application]. Stop running the command. Error: failed to pull docker image: Command /bin/sh -c docker pull [URL_ID].dkr.ecr.us-east-1.amazonaws.com/app-backend:latest failed with error exit status 1. Stderr:failed to register layer: Error processing tar file(exit status 1): write /root/.cache/pip/http/5/e/7/3/b/[long number]: no space left on device

本地手动执行docker pull [URL_ID].dkr.ecr.us-east-1.amazonaws.com/app-backend:latest响应正常。我的Dockerrun.aws.json文件内容如下:

{
    "AWSEBDockerrunVersion": "1",
    "Image": {
      "Name": "[URL_ID].dkr.ecr.us-east-1.amazonaws.com/app-backend",
      "Update": "true"
    },
    "Ports": [
      {
        "ContainerPort": 5000,
        "HostPort": 5000
      }
    ]
}
原因分析与解决建议

核心原因

错误日志中的no space left on device明确说明:EB实例的磁盘空间不足,导致拉取镜像时无法完成镜像层的解压与写入操作。本地拉取正常是因为本地机器磁盘空间充足,和EB实例的资源情况无关。

解决步骤

  • 升级EB实例磁盘容量:在AWS控制台找到对应EB环境,修改实例配置——选择磁盘容量更大的实例类型,或直接调整EBS卷大小(默认EB实例磁盘通常为8GB,镜像拉取解压后容易被占满)。
  • 优化Docker镜像体积:
    • 使用多阶段构建,仅保留运行时必需依赖,比如用python:3.11-slim作为基础镜像,剔除编译工具等冗余文件。
    • 在Dockerfile中加入缓存清理命令,比如pip install后执行rm -rf /root/.cache/pip,减少镜像层大小。
  • 清理EB实例旧资源:若暂时不想升级实例,可手动连接到EB实例,执行docker system prune -a清理无用镜像、容器和卷,释放空间后重新部署。
  • 调整EB部署策略:确保部署时不会保留过多旧版本应用镜像,避免重复占用磁盘空间。

内容的提问来源于stack exchange,提问作者Math

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 02:45:35