Deploying a Containerized App on AWS, GCP, and Azure

Take one container image from your laptop to a public HTTPS URL on ECS Express Mode, Cloud Run and Azure Container Apps, step by step.

Cloud

The last article compared container orchestration services on paper. This one is practical: you take one small web app, package it once, and run it on all three clouds behind a public HTTPS URL. Along the way you see where the providers line up closely and where each one asks for something different.

The target on each cloud is the simplest platform that turns an image into a URL: Amazon ECS Express Mode, Google Cloud Run and Azure Container Apps. None of them needs a Kubernetes cluster, and all three are reasonable places to run a real stateless service, not just a demo.

What you are deploying

The app is the Flask service built in Introduction to Containers and Docker. It returns a small JSON response on / and ok on /healthz, and gunicorn serves it on port 8080. One change makes it friendlier to cloud platforms: it reads the port from the PORT environment variable when one is set, and falls back to 8080.

# app.py
import os
from flask import Flask

app = Flask(__name__)

@app.get("/")
def hello():
    return {"message": "hello from a container", "host": os.uname().nodename}

@app.get("/healthz")
def health():
    return "ok"
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py .

RUN useradd --create-home appuser
USER appuser

EXPOSE 8080
# Shell form so ${PORT} is expanded at start time
CMD exec gunicorn --bind "0.0.0.0:${PORT:-8080}" --workers 2 app:app

The exec matters. It replaces the shell with gunicorn, so gunicorn runs as process 1 and receives the SIGTERM that every platform sends when it stops a container. Without it, the shell receives the signal, gunicorn never hears it, and in-flight requests are cut off when the platform gives up and kills the container.

The flow on every cloud

Each deployment follows the same four steps. Only the tool names change.

flowchart LR
    SRC["Code and Dockerfile"] --> BLD["Build image"]
    BLD --> REG["Push to registry"]
    REG --> RUN["Create service"]
    RUN --> URL["Public HTTPS URL"]
StepAWSGoogle CloudAzure
RegistryAmazon ECRArtifact RegistryAzure Container Registry
Build in the cloudCodeBuild (optional)Cloud BuildACR Tasks (az acr build)
Run the serviceECS Express Mode on FargateCloud RunAzure Container Apps
Identity for pulling imagesTask execution roleCloud Run service agentManaged identity with AcrPull
LogsCloudWatch LogsCloud LoggingLog Analytics

Build once for the right architecture

If you build on an Apple silicon Mac, your image defaults to linux/arm64. Cloud Run and the default Fargate configuration expect linux/amd64, and an arm64 image fails at start with an exec format error. Build for the target explicitly:

docker buildx build --platform linux/amd64 -t hello-web:1.0 .
docker run --rm -p 8080:8080 hello-web:1.0   # test locally first
curl http://localhost:8080/healthz

Tag images with a version, not just latest. Every platform here records the image reference on each revision or deployment, and a meaningful tag is what lets you see later which code was running and roll back to it.

A Dockerfile ends with CMD gunicorn --bind 0.0.0.0:$PORT app:app in shell form, without exec. What goes wrong when the platform scales the container in?

  • The PORT variable is never expanded
  • The shell receives SIGTERM instead of gunicorn, so requests are cut off when the container is killed
  • The image will not build on amd64

Correct! Shell form runs gunicorn as a child of sh, which does not forward signals, so adding exec makes gunicorn process 1 and lets it shut down cleanly.

Google Cloud: Cloud Run

Cloud Run is the shortest path of the three, so it is a good place to start. The commands assume you have run gcloud init against a project with billing enabled; Setting Up Free Accounts on AWS, GCP, and Azure covers that.

Create a registry and push the image

PROJECT_ID=$(gcloud config get-value project)
REGION=us-central1

gcloud services enable run.googleapis.com artifactregistry.googleapis.com

gcloud artifacts repositories create apps \
  --repository-format=docker \
  --location=$REGION

# Let Docker authenticate to Artifact Registry with your gcloud credentials
gcloud auth configure-docker $REGION-docker.pkg.dev

IMAGE=$REGION-docker.pkg.dev/$PROJECT_ID/apps/hello-web:1.0
docker tag hello-web:1.0 $IMAGE
docker push $IMAGE

Deploy

gcloud run deploy hello-web \
  --image $IMAGE \
  --region $REGION \
  --allow-unauthenticated \
  --min-instances 0 \
  --max-instances 5

The command prints a service URL ending in run.app, with a managed TLS certificate already in place. A few things happened without you asking:

  • Cloud Run set PORT=8080 in the container, which is why the Dockerfile reads it.
  • The Cloud Run service agent pulled the image. Because the repository is in the same project, it already has permission.
  • A new revision was created and given all the traffic. Each later deploy creates another revision, and you can split traffic between them or send everything back to an older one.
  • --allow-unauthenticated granted the Cloud Run Invoker role to allUsers. Leave it off for internal services, and callers will need an identity token.

The service runs with the project’s default compute service account unless you pass --service-account. For anything beyond a demo, create a dedicated service account with only the roles the app needs, as described in GCP Identity and Access Management.

If you’d rather skip the local build entirely, gcloud run deploy hello-web --source . uploads the directory, builds it with Cloud Build and deploys the result in one step.

Update and roll back

# Ship version 1.1
gcloud run deploy hello-web --image $REGION-docker.pkg.dev/$PROJECT_ID/apps/hello-web:1.1 --region $REGION

# List revisions, then send all traffic back to the previous one
gcloud run revisions list --service hello-web --region $REGION
gcloud run services update-traffic hello-web --region $REGION \
  --to-revisions hello-web-00001-abc=100

Revision names include a generated suffix; copy the real one from the list output.

Azure: Container Apps

Container Apps groups apps into an environment, which is the shared network and logging boundary. Apps in the same environment can reach each other by name, and the environment sends logs to a Log Analytics workspace.

One-time setup

az extension add --name containerapp --upgrade
az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights

RG=rg-hello-web
LOCATION=eastus2
ACR=hellowebacr$RANDOM   # registry names are global and alphanumeric only

az group create --name $RG --location $LOCATION
az acr create --name $ACR --resource-group $RG --sku Basic

Build the image in the registry

Instead of pushing from your machine, you can let ACR Tasks build the image from your source directory. It builds for linux/amd64 by default, so the architecture issue from earlier disappears.

az acr build --registry $ACR --image hello-web:1.0 .

If you already built the image locally, az acr login --name $ACR followed by docker tag and docker push works the same way.

Create the environment and the app

az containerapp env create \
  --name env-hello \
  --resource-group $RG \
  --location $LOCATION

az containerapp create \
  --name hello-web \
  --resource-group $RG \
  --environment env-hello \
  --image $ACR.azurecr.io/hello-web:1.0 \
  --registry-server $ACR.azurecr.io \
  --registry-identity system \
  --target-port 8080 \
  --ingress external \
  --min-replicas 0 \
  --max-replicas 5

az containerapp show --name hello-web --resource-group $RG \
  --query properties.configuration.ingress.fqdn --output tsv

--registry-identity system gives the app a system-assigned managed identity and uses it to pull from the registry, so no registry password is stored in the app’s configuration. That is the same pattern as Workload ID on AKS: Azure resources authenticate as Entra identities, not with keys. Azure Identity and Access Management explains the model.

--target-port tells ingress where the container listens. Container Apps does not set PORT for you, so the Dockerfile’s fallback to 8080 is what makes the two agree. With --min-replicas 0, the app scales to zero after a period without requests and the first request afterwards waits for a cold start.

az containerapp up can do most of the above in one command, creating the resource group, environment and registry if they don’t exist. It is fine for experiments; the explicit commands are easier to read in a script and to reproduce later.

Update and roll back

az containerapp update --name hello-web --resource-group $RG \
  --image $ACR.azurecr.io/hello-web:1.1

az containerapp revision list --name hello-web --resource-group $RG --output table

Each change to the container template creates a new revision. In the default single-revision mode, the new one replaces the old once it is ready. Switch to multiple-revision mode (az containerapp revision set-mode --mode multiple) when you want to split traffic for a canary or keep an older revision available for instant rollback.

An app listens on the port in the PORT environment variable and has no default. It works on Cloud Run but fails its health checks on Azure Container Apps. What is the likely cause?

  • Container Apps only supports port 80
  • The image was built for the wrong architecture
  • Container Apps does not inject PORT, so the app never binds to the target port

Correct! Cloud Run sets PORT automatically, but Container Apps routes to the target port you configure without setting that variable, so a sensible default in the app avoids the mismatch.

AWS: ECS Express Mode

On AWS, the closest equivalent is ECS Express Mode, covered in AWS Elastic Container Service (ECS) and EKS. From an image and a few settings, it creates an ECS service on Fargate, an Application Load Balancer with HTTPS, security groups and an auto scaling policy. There is no charge for Express Mode itself; you pay for the Fargate tasks, load balancer and other resources it creates.

The main difference from the other two clouds is that you create the IAM roles yourself before the first deployment.

Push the image to ECR

REGION=us-east-1
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
REGISTRY=$ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com

aws ecr create-repository --repository-name hello-web --region $REGION

aws ecr get-login-password --region $REGION \
  | docker login --username AWS --password-stdin $REGISTRY

docker tag hello-web:1.0 $REGISTRY/hello-web:1.0
docker push $REGISTRY/hello-web:1.0

Create the two roles

Express Mode needs a task execution role, which ECS uses to pull the image and write logs, and an infrastructure role, which ECS uses to create the load balancer, security groups and scaling policy in your account. Both are trusted by ECS and use AWS managed policies.

cat > ecs-trust.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "ecs-tasks.amazonaws.com" },
      "Action": "sts:AssumeRole"
    }
  ]
}
EOF

aws iam create-role --role-name ecsTaskExecutionRole \
  --assume-role-policy-document file://ecs-trust.json
aws iam attach-role-policy --role-name ecsTaskExecutionRole \
  --policy-arn arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy

sed 's/ecs-tasks.amazonaws.com/ecs.amazonaws.com/' ecs-trust.json > infra-trust.json

aws iam create-role --role-name ecsInfrastructureRoleForExpressServices \
  --assume-role-policy-document file://infra-trust.json
aws iam attach-role-policy --role-name ecsInfrastructureRoleForExpressServices \
  --policy-arn arn:aws:iam::aws:policy/service-role/AmazonECSInfrastructureRoleforExpressGatewayServices

If your account already has ecsTaskExecutionRole from earlier ECS work, skip creating it. New roles can take a minute to propagate; if the next command fails with an error about assuming a role, wait briefly and retry.

Deploy

aws ecs create-express-gateway-service \
  --service-name hello-web \
  --execution-role-arn arn:aws:iam::$ACCOUNT_ID:role/ecsTaskExecutionRole \
  --infrastructure-role-arn arn:aws:iam::$ACCOUNT_ID:role/ecsInfrastructureRoleForExpressServices \
  --primary-container "{\"image\": \"$REGISTRY/hello-web:1.0\", \"containerPort\": 8080}" \
  --health-check-path /healthz \
  --scaling-target '{"minTaskCount": 1, "maxTaskCount": 5}' \
  --region $REGION

Two settings here are easy to miss, because the defaults don’t match this app. The container port defaults to 80 and the health check path to /ping; without overriding both, the load balancer marks every task unhealthy and ECS keeps replacing them. CPU and memory default to 0.25 vCPU and 512 MiB, which is enough for this service; pass --cpu and --memory for anything heavier.

The response includes the service ARN and, under its active configuration, the public endpoint. Provisioning the load balancer takes a few minutes; aws ecs describe-express-gateway-service --service-arn <arn> shows the status, and the endpoint serves traffic once the service is active.

Note the minTaskCount of 1. An ECS service does not scale to zero, and the Application Load Balancer bills by the hour whether or not requests arrive. For a low-traffic service, that standing cost is the biggest difference between AWS and the other two platforms here.

Because Express Mode builds ordinary resources, you can open the generated service in the ECS console, look at its task definition and load balancer rules, and change them like any other ECS service. Updates go through aws ecs update-express-gateway-service, and each one rolls out as a new deployment with the previous configuration kept for rollback.

flowchart TB
    U["Client"] --> ALB["Application Load Balancer"]
    ALB --> T1["Fargate task"]
    ALB --> T2["Fargate task"]
    T1 -. "pull image" .-> ECR["Amazon ECR"]
    T1 -. "logs" .-> CW["CloudWatch Logs"]
    EX["Express Mode"] -->|"creates"| ALB
    EX -->|"creates"| SVC["ECS service"]
    SVC --> T1
    SVC --> T2

Comparing the three deployments

With the same image running in three places, the differences are easy to see.

ECS Express ModeCloud RunAzure Container Apps
Commands to first URLRegistry, two roles, one deployRegistry, one deployGroup, registry, environment, one deploy
Port handlingcontainerPort you set (default 80)Injects PORT, default 8080--target-port you set
Health checkALB path you set (default /ping)TCP startup probe by defaultProbes configurable on the app
Scale to zeroNoYesYes
Idle costTasks plus load balancerNone for computeNone for compute on Consumption
HTTPS endpointGenerated by Express Moderun.app URLEnvironment domain FQDN
Rollback unitDeploymentRevision with traffic splitRevision with traffic split
What you can edit afterwardsAll underlying ECS and ALB resourcesService settingsApp and environment settings

The pattern is consistent with the earlier comparison. Cloud Run asks the least of you and hides the most. Container Apps adds the environment as an explicit concept, which pays off once you have several apps that talk to each other. ECS Express Mode needs the most setup and costs something when idle, but it leaves you with standard AWS resources rather than a separate platform.

An Express Mode service keeps replacing its tasks, and the load balancer reports every target as unhealthy. The app listens on 8080 and serves /healthz. What should you check first?

  • That containerPort is 8080 and the health check path is /healthz, not the defaults of 80 and /ping
  • That the image tag is latest
  • That minTaskCount is set to zero

Correct! Express Mode defaults to port 80 and /ping, so an app that differs on either one fails the load balancer health check.

From commands to a pipeline

Running these commands by hand is the right way to learn them and the wrong way to ship. In practice, the same steps move into CI:

sequenceDiagram
    participant Dev as Developer
    participant CI as CI pipeline
    participant Reg as Registry
    participant Run as Container platform
    Dev->>CI: Push to main
    CI->>CI: Test and build image
    CI->>Reg: Push image tagged with commit
    CI->>Run: Deploy new image tag
    Run->>Run: Health check new revision
    Run-->>CI: Ready or rolled back

A few habits make that pipeline safer on any of the three clouds:

  • No long-lived keys in CI. GitHub Actions and similar systems can authenticate through OpenID Connect: an IAM role trust policy on AWS, Workload Identity Federation on Google Cloud, and a federated credential on an Entra app or managed identity on Azure. The pipeline gets short-lived credentials scoped to one job.
  • Tag with the commit. Using the Git commit SHA as the image tag ties every running revision back to exact source.
  • Give the deployer narrow permissions. It needs to push to one repository and update one service, not administer the account.
  • Describe infrastructure in code. Terraform, CloudFormation, Bicep or Pulumi keeps the registry, roles and service definitions reviewable, so the next environment is a copy rather than a reconstruction from shell history.

Cleaning up

Each of these keeps costing something while it exists, so remove what you don’t need.

# Google Cloud
gcloud run services delete hello-web --region us-central1
gcloud artifacts repositories delete apps --location us-central1

# Azure: deleting the group removes the app, environment, registry and workspace
az group delete --name rg-hello-web --yes

# AWS
aws ecs delete-express-gateway-service --service-arn <service-arn> --region us-east-1
aws ecr delete-repository --repository-name hello-web --force --region us-east-1

On AWS, confirm afterwards that the load balancer is gone, and set a budget alert on each account if you haven’t already. The billing guides for AWS, GCP and Azure show how.

Further reading

Key takeaways

  • The workflow is the same on every cloud: build an image, push it to the provider’s registry, create a service from it, and get an HTTPS URL.
  • Build for linux/amd64 unless you know the platform runs your architecture, and start the server with exec so it receives shutdown signals.
  • Have the app read PORT with a sensible default; Cloud Run injects it, while Container Apps and ECS route to whatever port you declare.
  • Cloud Run has the fewest steps. Container Apps adds an environment that groups related apps. ECS Express Mode needs IAM roles up front and leaves you with ordinary, editable ECS and load balancer resources.
  • Cloud Run and Container Apps scale to zero; an Express Mode service keeps at least one task and a load balancer running.
  • Override defaults that don’t match your app, especially the Express Mode port and health check path.
  • Move the commands into CI with OIDC federation and commit-tagged images before anything reaches production, and delete what you no longer use.

Part 6 of 6 · Container Services

  1. 01Introduction to Containers and Docker
  2. 02AWS Elastic Container Service (ECS) and EKS
  3. 03Google Kubernetes Engine (GKE)
  4. 04Azure Kubernetes Service (AKS)
  5. 05Comparing Container Orchestration Services
  6. 06Deploying a Containerized App on AWS, GCP, and Azure
Ready to check your understanding?Take the Fluffy Computing quiz
esc

Type to search all articles · ↑↓ to move · ↵ to open