Containers (1 / 60): As a DevOps engineer at ABC Industries, you are in charge of deploying a Node.js web service that communicates with a MongoDB database to Microsoft Azure. This service relies on environment variables DB_URL
and SECRET_TOKEN
for database connection and secure interactions, respectively. The service's Docker image is hosted on Docker Hub under abcindustries/ai-service-app
.
For deployment, an Azure Container App should be created under the name ai-service-app
, located in the westus2
region within the abc-industries
resource group. The app will run on port 8000 and needs DB_URL and SECRET_TOKEN set to mongodb://username:password@dbhost:27017/dbname
and sometoken
respectively. The container instance should have suitable CPU and memory specifications.
Considering these requirements, how would you employ Azure CLI to set up this Azure Container App?
Answer:
# Log into the Azure account
az login
# Upgrade the Azure CLI to the latest version
az upgrade
# Add and upgrade the containerapp extension
az extension add --name containerapp --upgrade
# Register the necessary providers as the microservice uses services for hosting APIs
az provider register --namespace Microsoft.App
# Create the 'dev' environment
az containerapp env create --resource-group MyResourceGroup --name dev
# Create the container application
az containerapp create \
--name ai-service-app \
--resource-group abc-industries \
--environment-variables DB_URL=mongodb://username:password@dbhost:27017/dbname SECRET_TOKEN=sometoken \
--docker-image abcindustries/ai-service-app \
--region westus2 \
--target-port 8000 \
--cpu <CPU_CORES> \
--memory <MEMORY_GB>
az containerapp create
gives you more control over the configuration and is suitable for setting up a new application or when making changes to an existing application in a production environment.