'Azure Container Instance is immediately killed on Startup

I am trying to run an azure container instance but it appears to be getting killed off the second I run it. This works fine in 2 other resource groups but not my production resource group where I see the following:

  • In events I see 'Successfully pulled image selenium/standalone-chrome:latest' with count 1 and then 'Started container' and then 'Killing container' with count 31. The times for started and killed are the same.
  • In logs, it just says 'No logs available'
  • The metrics for CPU and memory on the container never show any change from zero.

Looked at this article but the proposed solution didn't work: Azure Container Group Instance I have tried putting on both an empty directory volume and 2Gb of ram as advised here: https://github.com/SeleniumHQ/docker-selenium but nothing works.

This is the code I am using to create the container:

containerGroup = await azure.ContainerGroups.Define(containerName)
            .WithRegion("West Europe")
            .WithExistingResourceGroup(configuration.ContainerResourceGroup)
            .WithLinux()
            .WithPublicImageRegistryOnly()
            .WithEmptyDirectoryVolume("devshm")
            .DefineContainerInstance(containerName)
                .WithImage("selenium/standalone-chrome")
                .WithExternalTcpPorts(4444)
                .WithVolumeMountSetting("devshm", "/dev/shm")
                .WithMemorySizeInGB(2)
                .Attach()
            .WithDnsPrefix(configuration.AppServiceName + "container")
            .WithRestartPolicy(ContainerGroupRestartPolicy.OnFailure)
            .CreateAsync(cancellationToken);

How do I debug what is going wrong? What is wrong with the container?



Solution 1:[1]

In case this helps someone I renamed the "containerName" parameter in the above example from myinstance to myinstance1 and changed the region from West Europe to UK South. This fixed the issue. I can only think that Azure caches instances somehow to reduce start up times and the cached image I was using was poisoned somehow.

Solution 2:[2]

One issue could be the restart policy - have a look at the Microsoft restart policy troubleshooting on Microsoft's ACI troubleshooting page. According to the website under the Container continually exits and restarts (no long-running process) header in the page:

Container groups default to a restart policy of Always, so containers in the container group always restart after they run to completion. You may need to change this to OnFailure or Never if you intend to run task-based containers. If you specify OnFailure and still see continual restarts, there might be an issue with the application or script executed in your container.

In your case you may need to adjust the code as follows using the withStartingCommand:

containerGroup = await azure.ContainerGroups.Define(containerName)
            .WithRegion("West Europe")
            .WithExistingResourceGroup(configuration.ContainerResourceGroup)
            .WithLinux()
            .WithPublicImageRegistryOnly()
            .WithEmptyDirectoryVolume("devshm")
            .DefineContainerInstance(containerName)
                .WithImage("selenium/standalone-chrome")
                .WithExternalTcpPorts(4444)
                .WithVolumeMountSetting("devshm", "/dev/shm")
                .WithMemorySizeInGB(2)
                .WithStartingCommandLine("tail")
                .WithStartingCommandLine("-f")
                .WithStartingCommandLine("/dev/null")
                .Attach()
            .WithDnsPrefix(configuration.AppServiceName + "container")
            .WithRestartPolicy(ContainerGroupRestartPolicy.OnFailure)
            .CreateAsync(cancellationToken);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 johnstaveley
Solution 2