无法将Flask-Docker代码部署至AWS EB:已存配置文件仍报错
部署Flask-Docker到AWS EB时提示缺少Dockerfile/Dockerrun.aws.json的问题
错误日志
Creating application version archive "app-6c68-230807_154922". Uploading qube-flask-app/app-6c68-230807_154922.zip to S3. This may take a while. Upload Complete. 2023-08-07 20:49:24 INFO Environment update is starting. 2023-08-07 20:49:29 INFO Deploying new version to instance(s). 2023-08-07 20:49:32 ERROR Instance deployment: Both 'Dockerfile' and 'Dockerrun.aws.json' are missing in your source bundle. Include at least one of them. The deployment failed. 2023-08-07 20:49:32 ERROR Instance deployment failed. For details, see 'eb-engine.log'. 2023-08-07 20:49:35 ERROR [Instance: i-0d86da861e1f288e2] Command failed on instance. Return code: 1 Output: Engine execution has encountered an error.. 2023-08-07 20:49:35 INFO Command execution completed on all instances. Summary: [Successful: 0, Failed: 1]. 2023-08-07 20:49:35 ERROR Unsuccessful command execution on instance id(s) 'i-0d86da861e1f288e2'. Aborting the operation.
问题描述
本地同时存在Dockerfile和Dockerrun.aws.json文件,但无论使用AWS EB CLI部署还是手动压缩文件上传,均收到上述错误提示,已上传eb-engine.log供排查。
相关文件内容
Dockerfile
# Use the official Python image as a base image FROM python:3.9 # Set the working directory inside the container WORKDIR /app # Copy the requirements.txt file to the working directory COPY requirements.txt . # Install the required Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Expose the port that your Flask app will run on (default is usually 5000) EXPOSE 5000 # Command to start the Flask app with a volume mount CMD ["python", "-m", "flask", "run", "--host", "0.0.0.0"]
Dockerrun.aws.json
{ "AWSEBDockerrunVersion": "1", "Image": { "Name": "577826555055.dkr.ecr.us-east-1.amazonaws.com/qube-flask-app-dev:latest", "Update": "true" }, "Ports": [ { "ContainerPort": 80 } ] }
排查与解决方案
- 检查压缩包结构:确保Dockerfile和Dockerrun.aws.json位于压缩包的根目录,而非嵌套在子文件夹中。手动压缩时,直接选中目标文件压缩,不要压缩包含这些文件的父文件夹。
- CLI部署路径验证:执行
eb deploy前,用ls命令确认当前工作目录下存在这两个文件,避免在上级目录执行部署命令导致路径错误。 - 文件名大小写检查:AWS EB对文件名大小写敏感,确认文件名严格为
Dockerfile(首字母大写,无后缀)和Dockerrun.aws.json,无拼写或大小写错误。 - 排除规则检查:查看项目中的
.gitignore或.ebignore文件,确保这两个文件未被添加到排除列表,导致打包时未被包含进部署包。 - 端口一致性修正:Dockerfile中EXPOSE的端口为5000,但Dockerrun.aws.json中配置的ContainerPort为80,端口不匹配会导致后续访问失败,建议统一端口(例如将Dockerfile的EXPOSE改为80,或调整Dockerrun.aws.json的ContainerPort为5000)。
内容的提问来源于stack exchange,提问作者user17281101
相关产品推荐
相关产品推荐

