Overview
This tutorial walks you through building, containerizing, and deploying a simple Node.js web app to Azure Container Apps using the Azure CLI.
Prerequisites
- Azure Subscription (free tier works)
- Azure CLI 2.45+ (
az version
) - Docker Desktop or Docker Engine
- Node.js 20+ (
node -v
) - Git
Step 1 – Create the Node.js App
mkdir hello-container && cd hello-container
npm init -y
npm i express
cat > index.js <<'EOF'
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('👋 Hello from Azure Container Apps!');
});
app.listen(port, () => console.log(`Listening on ${port}`));
EOF
Step 2 – Dockerize the App
# Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node","index.js"]
Build and test locally:
docker build -t hello-container .
docker run -p 3000:3000 hello-container
# Open http://localhost:3000
Step 3 – Push Image to Azure Container Registry (ACR)
# Log in to Azure
az login
# Choose subscription (optional)
az account set --subscription "<SUBSCRIPTION_ID>"
# Create resource group
az group create -n rg-container-app -l eastus
# Create ACR
az acr create -g rg-container-app -n acrhellocontainer --sku Basic
# Log in to ACR
az acr login -n acrhellocontainer
# Tag & push image
docker tag hello-container acrhellocontainer.azurecr.io/hello-container:v1
docker push acrhellocontainer.azurecr.io/hello-container:v1
Step 4 – Deploy to Azure Container Apps
# Enable the Container Apps extension
az extension add -n containerapp
# Create environment
az containerapp env create -n ca-env -g rg-container-app --location eastus
# Deploy the container app
az containerapp create \
-n hello-ca \
-g rg-container-app \
--environment ca-env \
--image acrhellocontainer.azurecr.io/hello-container:v1 \
--ingress external \
--target-port 3000
Get the URL:
az containerapp show -n hello-ca -g rg-container-app --query properties.configuration.ingress.fqdn -o tsv
Step 5 – Verify the Deployment
Open the returned FQDN in a browser. You should see:
👋 Hello from Azure Container Apps!
Cleanup (Optional)
az group delete -n rg-container-app -y