简体   繁体   English

如何将具有多个 Docker 容器的应用程序部署到 AWS Elastic Beanstalk?

[英]How to deploy an app with multiple Docker containers to AWS Elastic Beanstalk?

I have a Django application whose docker image's Dockerfile is as follows:我有一个 Django 应用程序,其 docker 图像的Dockerfile如下:

FROM python:3.7

ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/

RUN pip3 install -r requirements.txt
COPY . /code/

ENV PORT=8000
EXPOSE 8000

Then, I have a docker-compose.yml file for defining other container images and dependencies for my Django application as follows:然后,我有一个docker-compose.yml文件,用于为我的 Django 应用程序定义其他容器映像和依赖项,如下所示:

version: '3'

services:
  web: &django_app
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    ports:
      - "80:8000"
    depends_on:
      - rabbitmq
  rabbitmq:
    image: rabbitmq:latest
  celery_worker:
    <<: *django_app
    command: celery -A DJingApp worker --loglevel=info
    ports: []
    depends_on:
      - rabbitmq

As you can see above, I've got to have 3 containers( web , rabbitmq , and celery_worker ) running at any point in time for my Django app to work.正如您在上面看到的,我必须在任何时间点运行 3 个容器( webrabbitmqcelery_worker )才能让我的 ZEF0F93C83E374876A61DA0D4D16F3 应用程序运行。

So, how do I deploy this project's Docker images to AWS Elastic Beanstalk and run them out there?那么,如何将该项目的 Docker 映像部署到 AWS Elastic Beanstalk 并在那里运行它们? Are there any changes that I will have to make to my Dockerfile or docker-compose.yml ?我必须对我的Dockerfiledocker-compose.yml进行任何更改吗? If yes, what are they?如果是,它们是什么?

It's quite challenging to deploy a multi-container app to Elastic Beanstalk.将多容器应用程序部署到 Elastic Beanstalk 非常具有挑战性。 You need a Dockerrun.aws.json version 2 configuration file which is an Elastic Beanstalk–specific JSON file that describes how to deploy a set of Docker containers as an Elastic Beanstalk application.您需要一个Dockerrun.aws.json版本 2 配置文件,它是一个 Elastic Beanstalk 特定的 JSON 文件,该文件描述如何将一组 Docker 容器部署为 Elastic Beanstalk 应用程序。

If you don't know how to create the configuration file I suggest reviewing the official page .如果您不知道如何创建配置文件,我建议您查看官方页面

And also you can use container transform utility to transform your docker-compose file to a Dockerrun.aws.json configuration file which I find very helpful.您还可以使用容器转换实用程序将docker-compose文件转换为Dockerrun.aws.json配置文件,我觉得这很有帮助。 You may need to make some changes in the autogenerated file.您可能需要对自动生成的文件进行一些更改。

And also to customize your environment you need to use .ebextensions .而且要自定义您的环境,您需要使用.ebextensions Such as defining your Django settings path, WSGI path, web server configurations, executing Django management commands before deployment and so.比如定义你的Django设置路径,WSGI路径,web服务器配置,部署前执行Django管理命令等等。

For detailed logs, I suggest using environment logs under:对于详细的日志,我建议使用以下环境日志:

Elastic Beanstalk - Environments - 'your-environment-name' - Logs Elastic Beanstalk - 环境 - '您的环境名称' - 日志

Note : I suggest using eb deploy for successful deployment since you need to deploy your source code in .zip file format.注意:我建议使用eb deploy来成功部署,因为您需要以.zip文件格式部署源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM