Azure container instance restarts perpetually. Image is based taken from azure container registry. Problem: One or more of the containers in 'express-app' are in a 'Waiting' state and may not be running.

Bhavesh Ittadwar 5 Reputation points
2024-07-15T23:25:20.2866667+00:00

Here are the files for a basic express app I am trying to containerize and deploy on the Azure container registry.

index.js

const express = require('express')
const morgan = require('morgan')

const app = express()
const port = process.env.PORT || 80;

app.use(morgan('combined'))

app.get('/', (req, res) => {
    res.json({
        message: 'Welcome to Cloud Cast backend'
    })
})

app.listen(port, () => {
    console.log(`Server is running on port ${port}`)
})

package.json

{
  "name": "cloud-cast-server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.19.2",
    "morgan": "^1.10.0"
  }
}

Dockerfile

FROM node:14

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 80

CMD ["node", "index.js"]

Commands used

  1. Create a container registry and push express-image to it
az acr create --name expressreg --resource-group cloud-cast-rg --sku Basic
az acr login --name expressreg
docker build -t express-image:v1 .
docker tag express-image:v1 
docker push expressreg.azurecr.io/express-image:v1
az acr update --name expressreg --admin-enabled true
  1. Create a container instance from the repository pushed to the container registry.
az container create \
  --resource-group cloud-cast-rg \
  --name express-app \
  --image expressreg.azurecr.io/express-image:v1 \
  --cpu 1 \
  --memory 1.5 \
  --registry-login-server expressreg.azurecr.io \
  --registry-username expressreg \
  --registry-password <your-registry-password> \
  --ports 80

(I entered the respective password, concealing it for the sake of privacy)

Problem:

Seeing the message:

One or more of the containers in 'express-app' are in a 'Waiting' state and may not be running. Click here to view container statuses. 

When I click it I am on the container tab and can observe that the container instance is terminating and restarting perpetually. The container is mostly in the waiting state.

Tried to access logs

az container logs --resource-group cloud-cast-rg --name express-app

Output: None

Tried to test the image locally:

docker run -p 80:80 expressreg.azurecr.io/express-image:v1

On 127.0.0.1:80 I get

{"message":"Welcome to Cloud Cast backend"}

Further debugging:

az container attach --name express-app --resource-group cloud-cast-rg

Output:

Container 'express-app' is in state 'Waiting'...
(count: 1) (last timestamp: 2024-07-15 22:58:08+00:00) pulling image "expressreg.azurecr.io/express-image:v1"
(count: 1) (last timestamp: 2024-07-15 22:58:28+00:00) Successfully pulled image "expressreg.azurecr.io/express-image:v1"
(count: 8) (last timestamp: 2024-07-15 23:07:20+00:00) Started container
(count: 8) (last timestamp: 2024-07-15 23:07:27+00:00) Killing container with id <container-id>

Container crash logs

az container show --name express-app --resource-group cloud-cast-rg

Output:

{
  "confidentialComputeProperties": null,
  "containers": [
    {
      "command": null,
      "environmentVariables": [],
      "image": "expressreg.azurecr.io/express-image:v1",
      "instanceView": {
        "currentState": {
          "detailStatus": "CrashLoopBackOff: Back-off restarting failed",
          "exitCode": null,
          "finishTime": null,
          "startTime": null,
          "state": "Waiting"
        },
        "events": [
          {
            "count": 1,
            "firstTimestamp": "2024-07-15T22:58:08+00:00",
            "lastTimestamp": "2024-07-15T22:58:08+00:00",
            "message": "pulling image \"expressreg.azurecr.io/express-image:v1\"",
            "name": "Pulling",
            "type": "Normal"
          },
          {
            "count": 1,
            "firstTimestamp": "2024-07-15T22:58:28+00:00",
            "lastTimestamp": "2024-07-15T22:58:28+00:00",
            "message": "Successfully pulled image \"expressreg.azurecr.io/express-image:v1\"",
            "name": "Pulled",
            "type": "Normal"
          },
          {
            "count": 8,
            "firstTimestamp": "2024-07-15T22:58:35+00:00",
            "lastTimestamp": "2024-07-15T23:07:20+00:00",
            "message": "Started container",
            "name": "Started",
            "type": "Normal"
          },
          {
            "count": 8,
            "firstTimestamp": "2024-07-15T22:58:41+00:00",
            "lastTimestamp": "2024-07-15T23:07:27+00:00",
            "message": "Killing container with id 910295e546c119c46ef36b1861bd0d9e4e608567d45b2f8092d317a7c15e5d6f.",
            "name": "Killing",
            "type": "Normal"
          }
        ],
        "previousState": {
          "detailStatus": "Error",
          "exitCode": 1,
          "finishTime": "2024-07-15T23:07:27.938000+00:00",
          "startTime": "2024-07-15T23:07:20.953000+00:00",
          "state": "Terminated"
        },
        "restartCount": 7
      },
      "livenessProbe": null,
      "name": "express-app",
      "ports": [],
      "readinessProbe": null,
      "resources": {
        "limits": null,
        "requests": {
          "cpu": 1.0,
          "gpu": null,
          "memoryInGb": 1.5
        }
      },
      "securityContext": null,
      "volumeMounts": null
    }
  ],
  "diagnostics": null,
  "dnsConfig": null,
  "encryptionProperties": null,
  "extensions": null,
  "id": "/subscriptions/cdab2bc2-370f-4d93-ba21-c793d78f9ecf/resourceGroups/cloud-cast-rg/providers/Microsoft.ContainerInstance/containerGroups/express-app",
  "identity": null,
  "imageRegistryCredentials": [
    {
      "identity": null,
      "identityUrl": null,
      "isDelegatedIdentity": false,
      "password": null,
      "server": "expressreg.azurecr.io",
      "username": "expressreg"
    }
  ],
  "initContainers": [],
  "instanceView": {
    "events": [],
    "state": "Running"
  },
  "ipAddress": null,
  "location": "eastus",
  "name": "express-app",
  "osType": "Linux",
  "priority": null,
  "provisioningState": "Succeeded",
  "resourceGroup": "cloud-cast-rg",
  "restartPolicy": "Always",
  "sku": "Standard",
  "subnetIds": null,
  "tags": {},
  "type": "Microsoft.ContainerInstance/containerGroups",
  "volumes": null,
  "zones": null 
}


Pardon the big gibberish o/p. The bottom line is the 'CrashLoopBackOff: Back-off restarting failed' message.

I have spent countless hours trying to get to the bottom of this. Someone please help.

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
425 questions
Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
672 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bhavesh Ittadwar 5 Reputation points
    2024-07-18T17:06:20.7166667+00:00

    This problem is specific to people running docker on arm64 architecture. So basically on M1/M2/M3 apple chips. The docker image on such devices is built using the arm64 platform and this image doesn't work on the azure container registry as they typically have the amd64 architecture.

    To check your current architecture you can run uname -m locally. If you get arm64 as an output, it's likely that the container instance or the container app built from this image will fail and the app will exit with ExitCode 1.

    So to solve this, once you have built and tested your container locally. You need to run docker buildx build --platform linux/amd64 -t <container-registry-name>.azurecr.io/<container-image-name>:<container-image-tag> . --push. This will build the image with the correct platform and push it to the respective registry, thanks to the --push flag. My app is now live :)

    1 person found this answer helpful.
    0 comments No comments

  2. Nikhil Duserla 970 Reputation points Microsoft Vendor
    2024-07-17T19:17:14.6766667+00:00

    Hi Bhavesh Ittadwar,

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    We understand from your query that you are experiencing an issue One or more of the containers in 'express-app' are in a 'Waiting' state and may not be running.

    We've addressed your query, and it's functioning well on our end. Please find below screenshot and output for your reference. User's image azureuser@test231:~$ az container show --name test2121 --resource-group testrg2

    {

    "confidentialComputeProperties": null,

    "containers": [

    {
    
      "command": null,
    
      "environmentVariables": [],
    
      "image": "testingacr2121.azurecr.io/nike:latest",
    
      "instanceView": {
    
        "currentState": {
    
          "detailStatus": "",
    
          "exitCode": null,
    
          "finishTime": null,
    
          "startTime": "2024-07-17T18:19:59.179000+00:00",
    
          "state": "Running"
    
        },
    
        "events": [
    
          {
    
            "count": 1,
    
            "firstTimestamp": "2024-07-17T18:19:08+00:00",
    
            "lastTimestamp": "2024-07-17T18:19:08+00:00",
    
            "message": "pulling image \"testingacr2121.azurecr.io/nike@sha256:a8ebe9f4e8e07b7d7d2470a36422840148ed9cc98e386c4d771600d7e7e8166b\"",
    
            "name": "Pulling",
    
            "type": "Normal"
    
          },
    
          {
    
            "count": 1,
    
            "firstTimestamp": "2024-07-17T18:19:50+00:00",
    
            "lastTimestamp": "2024-07-17T18:19:50+00:00",
    
            "message": "Successfully pulled image \"testingacr2121.azurecr.io/nike@sha256:a8ebe9f4e8e07b7d7d2470a36422840148ed9cc98e386c4d771600d7e7e8166b\"",
    
            "name": "Pulled",
    
            "type": "Normal"
    
          },
    
          {
    
            "count": 1,
    
            "firstTimestamp": "2024-07-17T18:19:59+00:00",
    
            "lastTimestamp": "2024-07-17T18:19:59+00:00",
    
            "message": "Started container",
    
            "name": "Started",
    
            "type": "Normal"
    
          }
    
        ],
    
        "previousState": null,
    
        "restartCount": 0
    
      },
    
      "livenessProbe": null,
    
      "name": "test2121",
    
      "ports": [
    
        {
    
          "port": 80,
    
          "protocol": "TCP"
    
        }
    
      ],
    
      "readinessProbe": null,
    
      "resources": {
    
        "limits": null,
    
        "requests": {
    
          "cpu": 1.0,
    
          "gpu": null,
    
          "memoryInGb": 1.5
    
        }
    
      },
    
      "securityContext": null,
    
      "volumeMounts": null
    
    }
    

    ],

    "diagnostics": null,

    "dnsConfig": null,

    "encryptionProperties": null,

    "extensions": null,

    "id": "/subscriptions/b535c78c-d69c-4f2b-bc70-584d848895fd/resourceGroups/testrg2/providers/Microsoft.ContainerInstance/containerGroups/test2121",

    "identity": null,

    "imageRegistryCredentials": [

    {
    
      "identity": null,
    
      "identityUrl": null,
    
      "isDelegatedIdentity": false,
    
      "password": null,
    
      "server": "testingacr2121.azurecr.io",
    
      "username": "testingacr2121"
    
    }
    

    ],

    "initContainers": [],

    "instanceView": {

    "events": [],
    
    "state": "Running"
    

    },

    "ipAddress": {

    "autoGeneratedDomainNameLabelScope": null,
    
    "dnsNameLabel": null,
    
    "fqdn": null,
    
    "ip": "4.213.206.176",
    
    "ports": [
    
      {
    
        "port": 80,
    
        "protocol": "TCP"
    
      }
    
    ],
    
    "type": "Public"
    

    },

    "location": "centralindia",

    "name": "test2121",

    "osType": "Linux",

    "priority": null,

    "provisioningState": "Succeeded",

    "resourceGroup": "testrg2",

    "restartPolicy": "OnFailure",

    "sku": "Standard",

    "subnetIds": null,

    "tags": {},

    "type": "Microsoft.ContainerInstance/containerGroups",

    "volumes": null,

    "zones": null

    }

    Please ensure that you have correctly executed the docker build and docker run commands before pushing the image to ACR.

    If you have any further queries, do let us know.

    If the answer is helpful, please click "Accept Answer" and "Upvote it."