1

We have an Azure Container Instance which holds a container for RabbitMQ. The IP address of the container keeps changing, which makes the rabbitmq server unreachable. Is there a way to make this static? do we need to add a DNS on top of the IP address if this can be made static?

Rafael
  • 1,099
  • 5
  • 23
  • 47

2 Answers2

2

As pointed out by @evidalpe, you can't assign a static IP address to a container instance. However, you can easily assign a static/predictable DNS name using dnsNameLabel. I find this much more convenient than using the IP address.

Example:

customdnslabel.westeurope.azurecontainer.io

You can set the DNS name label when creating the container instance, and also update the label for an existing instance. You cannot edit it using the portal, but it is shown as "FQDN" afterwards.

Azure CLI Example - Works for create and update. Azure CLI can also be executed using the Cloud Shell.

az container create -g myresourcegroup -n mycontainerinstancename --dns-name-label customdnslabel --image rabbitmq

Bicep Template:

resource mycontainerinstance 'Microsoft.ContainerInstance/containerGroups@2021-03-01' = {
  name: 'mycontainerinstancename'
  location: location
  properties: {
    osType: 'Linux'
    restartPolicy: 'Always'
    ipAddress: {
      dnsNameLabel: 'customdnslabel'
      type: 'Public'
      ports: [
        // ...
      ]
    }
    containers: [
      {
        name: 'mycontainer'
        properties: {
          image: image
          resources: {
            requests: {
              cpu: cpus
              memoryInGB: memory
            }
          }
          ports: [
            // ...
          ]
        }
      }
    ]
Alex AIT
  • 17,361
  • 3
  • 36
  • 73
  • Where is this supposed to be run from? – Rafael Sep 21 '22 at 10:19
  • 1
    @Rafael you can set dnsNameLabel pretty much wherever you are currently creating your container instance (except for the portal UI. Bicep is just one option to create and update the container. I'll update the answer with another example using Azure CLI. – Alex AIT Sep 21 '22 at 18:02
  • Thank you, hit this problem a couple of times, and this resolved it for me :) – Max Hamulyák Feb 17 '23 at 14:43
1

This is a known issue and several solutions have been proposed so far:

Static IP address for Azure Container Intances

Attaching a static ip address to Azure Container Instance

Another solution is setting up an Azure function that periodically checks the Container Instance IP, and when it changes, the function updates the Server IP accordingly.

A container orchestration system like Kubernetes could help overcoming the issue as well.

evidalpe
  • 11
  • 3