distributed systems & service orientated architectures: create lots of independent decoupled services.
Containers are good for running these.
Features
Popular with microservices. Pipeline:
ECS Runs containers on a cluster.
Cluster is logical grouping of tasks or services.
Containers defined in task definition.
Task definitions can run individual tasks, or tasks in a service.
A service is something which lets you run a specified number of tasks simultaneously in a cluster.
ECS Task definition: blueprint to launch docker container
ECS Task: Same as a container. Can support multiple running containers. Eg. wordpress task, mySQL task, application task.
ECS Service: used to define scaling and control tasks
Image: sits in Elastic Container Registry, docker hub, or custom.
Fargate runs tasks and services on serverless, or ECS launch type runs on EC2.
Task definition in JSON. Describes one or more containers, and their parameters (name, image, memory size, etc)
ECS task scheduler places tasks on the cluster. Different scheduling options available, e.g. define a service which maintains a specified number of tasks in the service.
Can register EC2 instances to the cluster, or run on Fargate serverless.
EC2 instances run Container Agent to communicate with ECS. This comes with ECS optimised AMI, or install yourself (Linux or windows)
Create a cluster, task definition, run the task and if goes to registry and pulls the task down.
ECS CLI different from AWS CLI
EC2 launch type: Lower level, control EC2, file storage, do teh management, granular control
Can have multiple tasks in a container wanting the same default port, e.g. Apache an nginx. The instance takes care of this, and maps to different ports. Also the ALB listens on a single port, HTTP 80, so need to set up the ALB to use rule based routing and paths. Can't do that with a network load balancer.
Specify IAM role for a container to use for a task. The tasks can then use AWS CLI. Use TaskRoleArn override.
New EC2 instance
SSH into it
sudo yam update -y (update EC2)
AWS configure (set up permissions: to set access key id for AWS CLI)
sudo amazon-linux-extra install docker
sudo service docker start
sudo systemctl enable docker (ensures restarts after a reboot of instance)
sudo usermod -a -G docker ec2-user (allows you to run commands as ec2-user rather than root)
docker info (if permissions issues, shutdown and restart instance with sudo shutdown -r now)
create Dockerfile (e.g. use ubuntu, install apache, expose a port, run apache)
docker build -t jb-container . (builds the image from Dockerfile)
docker run -t -i -p 80:80 jb-container (runs the image)
-> working docker image in a container.
Then want to copy the container to ECR
aws ecr create-repository --repository-name jer-ecr (created repository)
get repository urn
docker push (loads image)
Start in ECS:
ECS clusters, configure a new one, fargate type.
docker image uri
runs