14. Elastic Container Service

After you have published your docker images, you can use docker to publish your technology stack. First, you must create an ecs context.

docker context ls
docker context create ecs myecscontext
docker context use myecscontext

You can then define a technology stack in a docker-compose.yml file like the following to deploy.

 1version: "3.7"
 2services:
 3  db:
 4    image: ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/fs-demo-db:latest
 5    container_name: fs-demo-db
 6    volumes:
 7      - fs_demo_db:/var/lib/mysql
 8    environment:
 9      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
10    deploy:
11      resources:
12        limits:
13          cpus: '2'
14          memory: 4096M
15  rest:
16    image: ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/fs-demo-rest:latest
17    container_name: fs-demo-rest
18    environment:
19      - DATABASE_URL=${DATABASE_URL}
20    depends_on:
21      - db
22    deploy:
23      resources:
24        limits:
25          cpus: '2'
26          memory: 4096M
27  ng:
28    image: ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/fs-demo-www:latest
29    container_name: fs-demo-www
30    ports:
31      - "80:80"
32    depends_on: 
33      - rest
34    deploy:
35      resources:
36        limits:
37          cpus: '0.25'
38          memory: 512M
39volumes:
40  fs_demo_db:
41    external: true
42    name: ${MYSQL_VOLUME}
43networks:
44  default:
45    external: true
46    name: ${AWS_SECURITY_GROUP}
47x-aws-vpc: ${AWS_VPC}

Note that you can externalize values in a file .env.

This command will bring up your techonology stack in ECS.

docker compose up

You can check what is running as follows.

docker compose ps

You can bring down the cluster as follows.

docker compose down