01 - Run Locally with Docker¶
Before deploying to Azure Container Apps, validate your Node.js app in a container locally. This catches image, dependency, and port issues early.
Infrastructure Context
Service: Container Apps (Consumption) | Network: VNet integrated | VNet: ✅
This tutorial assumes a production-ready Container Apps deployment with a custom VNet, ACR with managed identity pull, and private endpoints for backend services.
flowchart TD
INET[Internet] -->|HTTPS| CA["Container App\nConsumption\nLinux Node 18 LTS"]
subgraph VNET["VNet 10.0.0.0/16"]
subgraph ENV_SUB["Environment Subnet 10.0.0.0/23\nDelegation: Microsoft.App/environments"]
CAE[Container Apps Environment]
CA
end
subgraph PE_SUB["Private Endpoint Subnet 10.0.2.0/24"]
PE_ACR[PE: ACR]
PE_KV[PE: Key Vault]
PE_ST[PE: Storage]
end
end
PE_ACR --> ACR[Azure Container Registry]
PE_KV --> KV[Key Vault]
PE_ST --> ST[Storage Account]
subgraph DNS[Private DNS Zones]
DNS_ACR[privatelink.azurecr.io]
DNS_KV[privatelink.vaultcore.azure.net]
DNS_ST[privatelink.blob.core.windows.net]
end
PE_ACR -.-> DNS_ACR
PE_KV -.-> DNS_KV
PE_ST -.-> DNS_ST
CA -.->|System-Assigned MI| ENTRA[Microsoft Entra ID]
CAE --> LOG[Log Analytics]
CA --> AI[Application Insights]
style CA fill:#107c10,color:#fff
style VNET fill:#E8F5E9,stroke:#4CAF50
style DNS fill:#E3F2FD Local Development Workflow¶
graph LR
CODE[Source Code] --> BUILD[Docker Build]
BUILD --> CONT[Container]
CONT --> LOCAL[localhost:8000]
LOCAL --> HEALTH[Health Check] Prerequisites¶
- Docker Engine or Docker Desktop
- Node.js and npm installed
- Source code with a Dockerfile
Aim for local-cloud parity
Keep local container port mapping and environment variable names aligned with your Azure deployment settings. This reduces revision failures caused by mismatched runtime assumptions.
Step-by-step¶
-
Build the container image
-
Run the container locally
-
Verify health endpoint
You can also verify runtime metadata:
-
Inspect application logs
Expected output
To find the container ID:
docker ps
Local parity checklist¶
- Application listens on port
8000(or your configured container port) - Required environment variables are present
/healthreturns HTTP 200- No startup exceptions in container logs
Do not commit local secret files
If you create a local .env file for testing, keep sensitive values out of source control and use placeholder values in shared examples.
Advanced Topics¶
- Use multi-stage Docker builds to keep your production image lean and secure.
- Use
node --watchduring development to automatically restart the server on file changes. - Add local Redis or MongoDB via
docker-composeto mimic cloud dependencies.