Containers on AWS: Docker Basics, Amazon ECS, EKS, Fargate, ECR, Elastic Beanstalk and Lightsail

AWS Technical Essentials 50 min min read Updated: Nov 17, 2026 Beginner
Containers on AWS: Docker Basics, Amazon ECS, EKS, Fargate, ECR, Elastic Beanstalk and Lightsail
Beginner Topic 4 of 4

Virtual Machines vs Containers

Virtual machine (EC2)Container (Docker)
IncludesFull operating systemApp and its libraries only. Shares the host OS kernel
SizeGigabytesMegabytes
Start timeMinutesSeconds
IsolationStrong (separate OS)Process level
UseTraditional apps, full controlMicroservices, consistent deployments

A container packages your app with everything it needs, so it runs the same way on a laptop, a test server and production.

Docker in 5 Minutes

bash # Dockerfile # FROM python:3.12-slim # WORKDIR /app # COPY requirements.txt . # RUN pip install -r requirements.txt # COPY . . # CMD ["python", "app.py"] docker build -t myapp:1.0 . docker run -p 8080:8080 myapp:1.0 docker ps
  • Image: the read-only template. Container: a running copy of an image
  • Registry: where images are stored (Docker Hub or Amazon ECR)

Amazon ECR: Your Image Library

bash aws ecr create-repository --repository-name myapp aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 111111111111.dkr.ecr.ap-south-1.amazonaws.com docker tag myapp:1.0 111111111111.dkr.ecr.ap-south-1.amazonaws.com/myapp:1.0 docker push 111111111111.dkr.ecr.ap-south-1.amazonaws.com/myapp:1.0
  • Amazon ECR is a private, secure registry with image scanning and lifecycle rules
  • Integrates with IAM, ECS and EKS

Orchestration: ECS and EKS

Running one container is easy. Running hundreds, keeping them healthy, scaling and updating them needs an orchestrator.

ServiceWhat it isChoose it when
Amazon ECS (Elastic Container Service)AWS's own simple container orchestratorYou want the easiest way to run containers on AWS
Amazon EKS (Elastic Kubernetes Service)Managed KubernetesYou already use Kubernetes or want open-source portability
ECS termMeaning
ClusterGroup of capacity to run tasks
Task definitionBlueprint: image, CPU, memory, ports, environment
TaskA running instance of a task definition
ServiceKeeps a desired number of tasks running, connects to a load balancer

Where Do the Containers Run? EC2 or Fargate

Launch typeYou manageNotes
EC2The servers that run containersMore control, can be cheaper at scale
AWS FargateNothing about servers. Choose CPU and memory per taskServerless containers. Pay for task resources and time. Great for beginners

Other Ways to Run Apps

ServiceGood for
AWS Elastic BeanstalkUpload your code (Java, Python, Node.js, PHP, .NET, Docker) and AWS sets up servers, load balancer and scaling. Fast for web apps
AWS App RunnerRun a web app or API from source code or a container image with almost no setup
Amazon LightsailSimple virtual servers, databases and load balancers with fixed monthly prices, for small sites and learners
AWS LambdaShort event-driven code (previous lesson)
AWS BatchRun batch computing jobs at any scale
AWS OutpostsAWS infrastructure in your own data center

Which Compute Service Should I Pick?

NeedPick
Full control of OS and softwareEC2
Short code triggered by events, no serversLambda
Containers, easiest on AWSECS on Fargate
KubernetesEKS
Just upload my web appElastic Beanstalk or App Runner
Simple low-cost websiteLightsail
Big batch jobsAWS Batch

Run a Container on ECS Fargate (Outline)

  1. Push your image to ECR
  2. In ECS create a cluster (Fargate)
  3. Create a task definition with your image, 0.5 vCPU and 1 GB memory, and port 80
  4. Create a service with 2 tasks in two subnets and attach an Application Load Balancer
  5. Open the load balancer DNS name in the browser
  6. Update the image tag and let the service do a rolling update

Practice

  1. Build a small Docker image locally and run it
  2. Push it to a new ECR repository
  3. Run it on ECS Fargate behind a load balancer
  4. Deploy the same app to Elastic Beanstalk and compare the effort

Conclusion

Containers package apps consistently. Store images in ECR, run them with ECS or EKS, and choose Fargate for serverless containers. Beanstalk, App Runner and Lightsail are simpler ways to host apps. Pick the service that matches how much control you need.

Quick Summary: VM vs container; Docker; ECR; ECS and EKS; Fargate; other services; selection; outline.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators