In this blog, we will deploy a container using docker compose
in ECS cluster.
You can follow this blog to deploy a docker container in ECS directly.
Checkout my Youtube video on this blog.
Prerequisite
- Configure aws credential
- Install aws cli version 2
- Clone this git repo
- Local workstation
Agenda:
- Create new docker context
- Run docker compose to create a new ECS cluster
To run it from your local workstation, first you need to set the docker context to use the ECS to run the docker commands
Create new docker context
docker context create ecs myecs
docker context ls
docker context use myecs
Create a docker-compose.yaml
file and provide your image detail
version: '3.4'
services:
web:
image: public.ecr.aws/w0f5g4k6/javaweb:latest
ports:
- 8080
Below command will create a ECS cluster with all other components which are required for the application like
- ECS Cluster
- VPC & Security Groups
- Task Definitions
- Tasks
- Service
- Load Balancer
- Target Groups
docker compose up
NOTE: For this error unexpected status code [manifests latest]: 403 Forbidden. Make sure you have logged in for your ECR repository
Cluster name is created as per your project name.
Now you can see the container which is running
docker compose ps
You can browse the url
http://ecsde-loadb-3cgdft1z8sn-d49735caa398dc73.elb.us-east-2.amazonaws.com:8080/LoginWebApp-1/`
It has automatically created the security group as per the docker-compose
file and added the port
To clean up
docker compose down
This will delete your cluster and all components.