Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

CL
Cloud (AWS, GCP, Azure)
0/12 completed
Beginner
What is cloud computing?AWS, Google Cloud and Azure comparedAccounts, billing alerts and the CLI
Intermediate
Identity and access (IAM)Virtual machinesObject storageNetworking: VPCs, subnets and load balancersManaged databases
Advanced
Serverless: functions, queues and eventsContainers in the cloud
Pro
Infrastructure as codeCost control, security and reliability
Tracks / Cloud (AWS, GCP, Azure) / Advanced

Containers in the cloud

Containers (from the Docker course) package an app with everything it needs, so it runs the same on your laptop and in production. Every cloud offers several ways to run them, from "just give me a URL" to full Kubernetes clusters. This lesson helps you choose, and walks through the usual path: build an image → push it to a registry → run it on a managed service.

The options, from simplest to most control

Service AWS Google Cloud Azure You manage
Serverless containers (scale to zero, URL included) App Runner, ECS on Fargate Cloud Run Container Apps Only the image
Container orchestration, no servers ECS on Fargate GKE Autopilot Container Apps Tasks, services, networking
Managed Kubernetes EKS GKE AKS Kubernetes workloads (and often node pools)
Containers on your own VMs ECS on EC2 GKE Standard AKS node pools Also the VMs

A good rule: start at the top, and move down only when you need what the lower levels offer. Most web apps and APIs run happily on Cloud Run, Container Apps or ECS Fargate. Kubernetes pays off for large platforms with many services and teams (and has its own course on this site).

Step 1: a container registry

Images are stored in a private registry next to where they run: ECR (AWS), Artifact Registry (Google Cloud), ACR (Azure).

bash
repo=$(aws ecr create-repository --repository-name shop-api --image-scanning-configuration scanOnPush=true \
  --image-tag-mutability IMMUTABLE --query "repository.repositoryUri" --output text)
echo "$repo" | sed -E 's/^[0-9]+\.dkr\.ecr\.[a-z0-9-]+\.amazonaws\.com/123456789012.dkr.ecr.ap-south-1.amazonaws.com/'
aws ecr describe-repositories --query "repositories[].[repositoryName, imageTagMutability, imageScanningConfiguration.scanOnPush]" --output text
Output
123456789012.dkr.ecr.ap-south-1.amazonaws.com/shop-api
shop-api	IMMUTABLE	True
  • Scan on push checks images for known vulnerabilities.
  • Immutable tags stop someone overwriting v1.4.2 with different code. Tag images with the Git commit or version, not just latest.

Pushing from your machine or CI:

bash
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-south-1.amazonaws.com
docker build -t shop-api:1.4.2 .
docker tag shop-api:1.4.2 123456789012.dkr.ecr.ap-south-1.amazonaws.com/shop-api:1.4.2
docker push 123456789012.dkr.ecr.ap-south-1.amazonaws.com/shop-api:1.4.2

💡 Build images for the CPU you'll run on: docker buildx build --platform linux/arm64 for Graviton/Axion/Cobalt (cheaper), linux/amd64 for Intel/AMD.

Step 2a: the easiest path, Cloud Run

On Google Cloud, one command builds, pushes and deploys a container, and returns an HTTPS URL. It scales to zero when idle:

bash
gcloud run deploy shop-api --source . --region asia-south1 --allow-unauthenticated \
  --memory 512Mi --min-instances 0 --max-instances 20 --set-env-vars "APP_ENV=prod"

Example output:

Building using Dockerfile and deploying container to Cloud Run service [shop-api] in project [learn-cloud-2026] region [asia-south1]
✓ Building and deploying... Done.
  ✓ Uploading sources...
  ✓ Building Container...
  ✓ Creating Revision...
  ✓ Routing traffic...
Done.
Service [shop-api] revision [shop-api-00001-xyz] has been deployed and is serving 100 percent of traffic.
Service URL: https://shop-api-abc123xyz-el.a.run.app

Azure Container Apps is similar: az containerapp up --name shop-api --source . --ingress external --target-port 8080.

The contract is simple: your container listens on the port in the PORT environment variable, is stateless (files and sessions go to storage and databases), and starts quickly.

Step 2b: ECS on Fargate (AWS)

ECS describes your app with three objects:

Object Is
Cluster A logical group for your services
Task definition A recipe: image, CPU, memory, port, environment, IAM role, logging
Service Keeps N copies (tasks) of a task definition running, replaces failed ones, and registers them with a load balancer
taskdef.json
{
  "family": "shop-api",
  "requiresCompatibilities": ["FARGATE"],
  "networkMode": "awsvpc",
  "cpu": "512",
  "memory": "1024",
  "runtimePlatform": { "cpuArchitecture": "ARM64", "operatingSystemFamily": "LINUX" },
  "executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
  "taskRoleArn": "arn:aws:iam::123456789012:role/shop-api-task",
  "containerDefinitions": [
    {
      "name": "api",
      "image": "123456789012.dkr.ecr.ap-south-1.amazonaws.com/shop-api:1.4.2",
      "portMappings": [{ "containerPort": 8080 }],
      "environment": [{ "name": "APP_ENV", "value": "prod" }],
      "secrets": [{ "name": "DATABASE_URL", "valueFrom": "arn:aws:secretsmanager:ap-south-1:123456789012:secret:shop/db-url" }],
      "healthCheck": { "command": ["CMD-SHELL", "wget -qO- localhost:8080/health || exit 1"], "interval": 15 },
      "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "/ecs/shop-api", "awslogs-region": "ap-south-1", "awslogs-stream-prefix": "api" } }
    }
  ]
}
bash
# the private subnets and app security group from the Networking lesson:
vpc=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --query Vpc.VpcId --output text)
sub_a=$(aws ec2 create-subnet --vpc-id "$vpc" --cidr-block 10.0.11.0/24 --availability-zone ap-south-1a --query Subnet.SubnetId --output text)
sub_b=$(aws ec2 create-subnet --vpc-id "$vpc" --cidr-block 10.0.12.0/24 --availability-zone ap-south-1b --query Subnet.SubnetId --output text)
sg=$(aws ec2 create-security-group --vpc-id "$vpc" --group-name app-sg --description "App" --query GroupId --output text)

aws ecs create-cluster --cluster-name shop --query "cluster.[clusterName, status]" --output text
aws ecs register-task-definition --cli-input-json file://taskdef.json \
  --query "taskDefinition.[family, revision, cpu, memory, runtimePlatform.cpuArchitecture]" --output text
aws ecs create-service --cluster shop --service-name shop-api --task-definition shop-api:1 --desired-count 2 \
  --launch-type FARGATE --network-configuration "awsvpcConfiguration={subnets=[$sub_a,$sub_b],securityGroups=[$sg],assignPublicIp=DISABLED}" \
  --query "service.[serviceName, desiredCount, launchType]" --output text
aws ecs list-services --cluster shop --query "serviceArns" --output text | sed -E 's/[0-9]{12}/123456789012/'
Output
shop	ACTIVE
shop-api	1	512	1024	ARM64
shop-api	2	FARGATE
arn:aws:ecs:ap-south-1:123456789012:service/shop/shop-api

Notice the two roles: the execution role lets ECS pull the image and read secrets; the task role is what your code can do (read S3, write to DynamoDB…). And secrets injects the database URL from Secrets Manager at start-up, so it's never in the image or the task definition.

Deploying a new version means registering a new task definition revision with the new image tag, then aws ecs update-service --task-definition shop-api:2. ECS starts new tasks, waits for them to pass health checks, then stops the old ones (a rolling deployment), and can roll back automatically if the new tasks fail.

Managed Kubernetes, briefly

When you need Kubernetes, the clouds run the control plane for you:

bash
gcloud container clusters create-auto shop --region asia-south1      # GKE Autopilot: no nodes to manage
az aks create --resource-group demo-rg --name shop --node-count 2 --generate-ssh-keys
eksctl create cluster --name shop --region ap-south-1 --nodes 2      # EKS with the eksctl tool

Then you deploy with standard Kubernetes manifests and kubectl, which work the same on all three. The Kubernetes course covers that in depth.

Production checklist

  • Images: small base images, non-root user, scanned, tagged by version (see the Docker course).
  • Configuration in environment variables; secrets from the cloud's secret manager.
  • Health checks so the platform restarts or replaces broken containers.
  • Logs to stdout/stderr: the platform collects them (CloudWatch, Cloud Logging, Azure Monitor).
  • Stateless containers: anything that must survive goes to a database or object storage.
  • Autoscaling on CPU, memory or requests, with sensible minimum and maximum counts.
  • Least-privilege task role / service account for the container.

Clean up

bash
aws ecs update-service --cluster shop --service shop-api --desired-count 0 > /dev/null
aws ecs delete-service --cluster shop --service shop-api --query "service.status" --output text
aws ecs delete-cluster --cluster shop --query "cluster.status" --output text
aws ecr delete-repository --repository-name shop-api --force --query "repository.repositoryName" --output text
Output
INACTIVE
INACTIVE
shop-api

Practice

  1. Containerise a small web app (or use one from the Docker course) and run it locally with the PORT variable.
  2. Push it to a registry on the cloud you use.
  3. Deploy it to Cloud Run, Container Apps or App Runner and open the URL.
  4. Explain the difference between an ECS task's execution role and its task role.
✎ Check your understanding

1.Which is usually the simplest way to run a containerised web app?

2.In ECS, what keeps a fixed number of copies of your container running?

3.Why use immutable image tags?

4.Where should a container get its database password?

← Serverless: functions, queues and events