1. Answers
  2. Deploy MongoDB on Azure Container Instances with TypeScript

How do I deploy the MongoDB Docker image on Azure Container Instances (ACI) with TypeScript?

In this guide, we will deploy a MongoDB Docker image on Azure Container Instances (ACI) using Pulumi and TypeScript. Azure Container Instances allow you to run containers without managing virtual machines, making it a simple and cost-effective way to run Docker containers in the cloud.

Key Points

  • We will use the @pulumi/azure-native package to define and deploy Azure resources.
  • We will create a container group with a single container running the MongoDB image.
  • The MongoDB container will be configured with environment variables to set the root username and password.

Detailed Steps

  1. Install Pulumi and Azure Native Provider: Ensure you have Pulumi installed and set up with the Azure Native provider.
  2. Define the Container Group: We will define a container group with a MongoDB container.
  3. Deploy the Resources: Using Pulumi, we will deploy the defined resources to Azure.
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure-native";

// Define the resource group
const resourceGroup = new azure.resources.ResourceGroup("mongo-rg", {
    location: "WestUS",
});

// Define the container group
const containerGroup = new azure.containerinstance.ContainerGroup("mongo-container-group", {
    resourceGroupName: resourceGroup.name,
    containerGroupName: "mongo-container-group",
    location: resourceGroup.location,
    osType: "Linux",
    containers: [{
        name: "mongo",
        image: "mongo:latest",
        ports: [{
            port: 27017,
            protocol: "TCP",
        }],
        resources: {
            requests: {
                cpu: 1.0,
                memoryInGB: 1.5,
            },
        },
        environmentVariables: [
            { name: "MONGO_INITDB_ROOT_USERNAME", value: "admin" },
            { name: "MONGO_INITDB_ROOT_PASSWORD", value: "password" },
        ],
    }],
    ipAddress: {
        ports: [{
            port: 27017,
            protocol: "TCP",
        }],
        type: "Public",
    },
});

// Export the IP address of the container group
export const ipAddress = containerGroup.ipAddress.apply(ip => ip?.ip);

Summary

In this guide, we successfully deployed a MongoDB Docker container on Azure Container Instances using Pulumi and TypeScript. We created a resource group and a container group that runs the MongoDB image with specific environment variables for the root username and password. The container is accessible via a public IP address, which is exported at the end of the script. This setup allows you to quickly deploy and manage MongoDB instances in the cloud without managing underlying infrastructure.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up