简体   繁体   English

在AWS ECS中使用docker-compose.yml和ecs-params.yml文件以不同的Lauch类型和卷安装来运行多个任务定义

[英]Run multiple task-definition using docker-compose.yml and ecs-params.yml file in AWS ECS with different lauch type and volume mounting

I have 4 docker images which i want to run on ECS. 我有4个要在ECS上运行的docker映像。 For my local system i use docker-compose file where i have multiple services. 对于我的本地系统,我使用docker-compose文件,其中有多个服务。

I want to do similar docker compose on ECS. 我想在ECS上执行类似的docker compose。

I want my database image to run on EC2 and rest on fargate and host the volume of database on EC2 and make sure each container can communicate with each-other using their name. 我希望我的数据库映像在EC2上运行,并在fargate上放置并在EC2上托管数据库量,并确保每个容器都可以使用其名称相互通信。 How do i configure my docker-compose.yml and ecs-param.yml file?? 如何配置docker-compose.yml和ecs-param.yml文件?

My sample docker-compose.yml file 我的样本docker-compose.yml文件

version: '2.1'
services:
  first:
    image: first:latest
    ports:
      - "2222:2222"
    depends_on:
       database:
        condition: service_healthy

  second:
    image: second:latest
    ports:
      - "8090:8090"
    depends_on:
       database:
        condition: service_healthy

  third:
    image: third:latest
    ports:
      - "3333:3333"

  database:
    image: database
    environment:
      MYSQL_ROOT_PASSWORD: abcde
      MYSQL_PASSWORD: abcde
      MYSQL_USER: user
    ports:
      - "3306:3306"
    volumes:
      - ./datadir/mysql:/var/lib/mysql
    healthcheck:
            test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
            timeout: 5s
            retries: 5
  1. I don't see how you connect containers with each other. 我看不到您如何相互连接容器。
    depends_on just tells Docker Compose the order to use when containers are started. depends_on只是告诉Docker Compose启动容器时要使用的顺序。
    You may have actual connection hardcoded inside containers, that's not good. 您可能在容器内部硬编码了实际的连接,这不好。
  2. Assuming Docker Compose file you shared containers can reach each other using their aliases from Compose file. 假设Docker Compose文件可以使您共享的容器可以使用Compose文件中的别名相互访问。
    For example third container can use database domain name to reach database container. 例如, third容器可以使用database域名访问database容器。
    So if you have such names hardcoded in your containers, it will work. 因此,如果您在容器中硬编码了此类名称,它将可以正常工作。 However usually people configure connection points(URLs) as environment variables in Docker Compose file. 但是,通常人们在Docker Compose文件中将连接点(URL)配置为环境变量。 In this case there is nothing hardcoded. 在这种情况下,没有任何硬编码。

  3. Hosting DB volume on EC2 can be a bad idea. 在EC2上托管数据库卷可能不是一个好主意。
    EC2 has 2 types of storage mapping - EBS and instance (based on S3). EC2有两种类型的存储映射-EBS和实例(基于S3)。 Instance storage is destroyed when EC2 instance is terminated. EC2实例终止时,实例存储将被破坏。 EBS has data preserves on EBS always. EBS始终在EBS上保留数据。
    So you either use EBS storage (and not EC2) or S3 that is not suitable for your need here. 因此,您可以使用不适合您的EBS存储(而不是EC2)或S3。

  4. Hosting DB in a container is very bad idea. 在容器中托管数据库是一个非常糟糕的主意。
    You can find the same info in a description of many DB images in Docker Hub. 您可以在Docker Hub中的许多数据库映像的描述中找到相同的信息。
    Instead you can use MySql as a service using AWS RDS . 相反,您可以使用AWS RDSMySql用作服务

  5. The problem you have now has nothing common with AWS and ECS now. 您现在遇到的问题现在与AWS和ECS无关。
    When you have Docker Compose running fine locally, you will get the same on ECS side. 当Docker Compose在本地运行良好时,您将在ECS端获得相同的结果。

You can see example of configuration via Compose file here . 您可以在此处通过Compose文件查看配置示例。

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

相关问题 将 Docker-Compose YML 部署到 AWS ECS - Deploy Docker-Compose YML to AWS ECS 每个 docker 撰写 yml 文件是否与 AWS ECS 容器兼容 - Does every docker compose yml file is compatible with AWS ECS containers AWS ECS-CLI docker-compose.yml depends_on 错误“services.nginx.depends_on.0 必须是字符串” - AWS ECS-CLI docker-compose.yml depends_on error "services.nginx.depends_on.0 must be a string" 如何从AWS中的开发docker-compose.yml转到已部署的docker-compose.yml - how to go from development docker-compose.yml to deployed docker-compose.yml in aws AWS SDK:ECS -> createTaskSet -> 如何设置最后一个任务定义版本 - AWS SDK : ECS -> createTaskSet -> how can I set last task-definition version AWS Elastic Beanstalk 与 AMI2 和 docker-compose.yml - AWS Elastic Beanstalk with AMI2 and docker-compose.yml 一个集群上的 AWS ECS 多任务定义 - AWS ECS multiple task definition on one cluster AWS ECS 运行最新任务定义 - AWS ECS run latest task definition AWS Elastic Beanstalk 不支持 docker-compose.yml 吗? - is docker-compose.yml not supported in AWS Elastic Beanstalk? 错误:撰写文件“./docker-compose.yml”无效,因为:services.jenkins.networks 包含无效类型 - ERROR: The Compose file './docker-compose.yml' is invalid because: services.jenkins.networks contains an invalid type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM