[英]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
depends_on
just tells Docker Compose the order to use when containers are started. depends_on
只是告诉Docker Compose启动容器时要使用的顺序。 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. 在这种情况下,没有任何硬编码。
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。
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 RDS将MySql用作服务 。
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.