【问题标题】:Deploying django docker container to elastic beanstalk将 django docker 容器部署到弹性 beantalk
【发布时间】:2020-12-05 11:14:03
【问题描述】:

我有一个配置了 nginx + gunicorn 的 django rest 框架应用程序。我可以使用 docker-compose up -d --build 在本地运行容器就好了,但我希望将 docker 映像部署到 AWS 弹性 beanstalk。

出于调试目的,我正在尝试eb local run,但我似乎收到了这个错误:

latest: Pulling from <user>/<repo>
Digest: sha256:15cec14272aca0b787c4209e3196b2e61d50732f6f4616f2cf50baa28b82c65c
Status: Image is up to date for <user>/<repo>:latest
docker.io/<user>/<repo>:latest
Sending build context to Docker daemon  316.7MB
Step 1/2 : FROM <user>/<repo>:latest
 ---> eex74e02e4e5
Step 2/2 : EXPOSE 8000
 ---> Using cache
 ---> 094f132e13a7
Successfully built 094f132e13a7
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
docker: invalid reference format.
See 'docker run --help'.
ERROR: CommandError - None

这是我的 Dockerrun.aws.json:

{
    "AWSEBDockerrunVersion": "1",
    "Image": {
      "Name": "<user>/<repo>:latest",
      "Update": "true"
    },
    "Ports": [
      {
        "ContainerPort": "8000"
      }
    ]
}

如果我实际部署到 EB,我会在日志中看到以下错误:

----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Aug 15 22:26:00 ip-172-31-24-230 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Aug 15 22:26:00 ip-172-31-24-230 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Aug 15 22:26:00 ip-172-31-24-230 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Aug 15 22:26:00 ip-172-31-24-230 web: ModuleNotFoundError: No module named 'application'
Aug 15 22:26:00 ip-172-31-24-230 web: [2020-08-15 22:26:00 +0000] [3815] [INFO] Worker exiting (pid: 3815)
Aug 15 22:26:00 ip-172-31-24-230 web: [2020-08-15 22:26:00 +0000] [3808] [INFO] Shutting down: Master
Aug 15 22:26:00 ip-172-31-24-230 web: [2020-08-15 22:26:00 +0000] [3808] [INFO] Reason: Worker failed to boot.
Aug 15 22:26:00 ip-172-31-24-230 web: [2020-08-15 22:26:00 +0000] [3820] [INFO] Starting gunicorn 20.0.4
Aug 15 22:26:00 ip-172-31-24-230 web: [2020-08-15 22:26:00 +0000] [3820] [INFO] Listening at: http://127.0.0.1:8000 (3820)

为什么会出现这个错误?

【问题讨论】:

  • 实际将其部署到 EB 时会发生什么?
  • nginx 遇到问题:502 bad gateway。但如果我只运行 docker-compose up -d 命令,它在本地运行良好
  • 您使用的是什么 EB 平台?好像是python,不是单docker?
  • 平台/Python 3.7 在 64 位 Amazon Linux 2/3.1.0 上运行,对不起,我是这个 aws 开发的新手,但是“单个 docker”是什么意思
  • 所以它不是docker环境,而是普通的python。

标签: django amazon-web-services docker amazon-elastic-beanstalk


【解决方案1】:

要在 EB 上使用 docker,您有两种选择:

由于您使用的是Dockerrun.aws.json v1,因此您应该使用Docker running on 64bit Amazon Linux 2/3.1.0 平台(单个docker),而不是Python 3.7 running on 64bit Amazon Linux 2/3.1.0

受支持的单 docker 平台列表为 here

在控制台中是:

【讨论】:

  • 有没有办法从命令行做到这一点?此外,我对应该运行单个 docker 容器还是多容器 docker 平台感到困惑。我目前有 3 个单独的容器(django+nginx+postgresdb),但都在一个图像中。
  • @humptydumpty 是的,你可以在 CLI 中使用它,就像你在 python 环境中一样。但是在出现提示时必须选择 docker env。如果使用 3 个容器,则需要 multidocker 容器 env。但是你还需要使用Dockerrun.aws.json v2,而不是像现在这样使用 v1。
  • 不错!我会试试看效果如何,谢谢!
  • @humptydumpty 没问题。如果答案有帮助,将不胜感激。对于新问题,您可以使用相关详细信息创建新问题。这将允许其他人也做出贡献并尝试提供帮助。
  • 快速问题:我使用 docker-compose 构建 3 个容器(api、nginx、postgres)并在本地运行。由于我需要一个多 docker 容器环境,因此我还需要将这些推送到 dockerhub。如何推送官方的 nginx 和 postgres 容器?还是我不推那些?
猜你喜欢
  • 2020-12-16
  • 2017-12-18
  • 2012-08-24
  • 2015-12-05
  • 2021-02-07
  • 2013-03-24
  • 2019-04-14
  • 1970-01-01
  • 2019-05-01
相关资源
最近更新 更多