Amazon ECS — Docker containers in AWS
ECS ( Cluster, Services, Tasks, Task Definition)
What’s a Docker?
Docker is a software development platform to deploy apps. Apps are packaged in containers that can be run on any OS.
Where Docker images are stored?
- In Docker Repositories
- Public: Docker Hub
- Private: Amazon ECR (Elastic Container Registry)
Docker Containers Management
- ECS: Amazon’s own platform
- Fargate: Amazon’s own serverless platform
- EKS: Amazon’s managed K8s
ECS Clusters Overview
- ECS Clusters are logical grouping of EC2 instances
- EC2 instances run the ECS agent (Docker container)
- The ECS agents register the instance to the ECS cluster
- The EC2 instance run a special AMI, made specifically for ECS
ECS Task Definition
- Task definitions are metadata in JSON form to tell ECS how to run Docket container
- It contains crucial information around
* Image Name
* Port Binding for Container and Host
* Memory and CPU required
* Environment variables
* Network information
* Logging configuration (ex Cloudwatch)
- ECS service help define how many tasks should run and how they should be run
- They ensure that the number of tasks desired is running g across our fleet of EC2 instances
- Thet can be linked to ELB/ NLB /ALB if needed
- ECR is a private Docker image repository
- Access is controlled through IAM
- login command
- Docker Push & Pull
Which of the commands must you run to pull existing Docker images from ECR?
$(aws ecr get-login --no-include-email)docker pull 1234567890.dkr.ecr.eu-west-1.amazonaws.com/demo:latest
The get-login command retrieves a token that is valid for a specified registry for 12 hours, and then it prints a docker login command with that authorization token. You can execute the printed command to log in to your registry with Docker, or just run it automatically using the $() command wrapper.
After you have logged in to an Amazon ECR registry with this command, you can use the Docker CLI to push and pull images from that registry until the token expires. The docker pull command is used to pull an image from the ECR registry.
docker buildis a command that is used to build Docker images from a Dockerfile.
- When launching an ECS Cluster, we have to create our EC2 instances; If we need to scale, we need to add EC2 instances
- So we manage infrastructure with Fargate, it’s all Serverless
- Just create task definitions, and AWS will run our containers for us.
- To scale, just increase the task number