I created a resource group and 4 container instances in Azure. They executed JMeter command on start up. 3 containers ran for the expected amount of time (12h), one of the containers was killed after a few hours. I want to docker inspect the killed container to find out the reason it was killed (I suspect OOM).
This is what I have done:
I logged in to Azure using az cli locally under PowerShell 7
I ran az container --help and can see available commands are:
I can't see a way to run docker inspect on a stopped container...
When I ran:
az container exec --exec-command "docker inspect" --name c3 --resource-group my_resource_group
I understandably get the BadRequestError: Container Group c3 is stopped
Can I docker inspect a stopped container in az cli?
Related
I can create a container group with:
az container create --os-type windows --resource-group dev --name win-sandbox --image mcr.microsoft.com/windows/servercore:1809
Then running ⬇️ it just exits immediately, but I would like an interactive Powershell prompt.
az container exec -g dev --name win-sandbox --exec-command "powershell.exe"
This is consistent with omitting -it from a docker run, but there is no such option for az container exec.
How do I get an interactive Powershell prompt?
How do I get an interactive Powershell prompt?
As per the Azure documentation , currently az container exec to open & execute in interactive mode not supported for windows machines.
az container exec Execute a command from within a running container of a container group. The most common use case is to open an interactive bash shell.
I am having code-server container running and I am running az container exec --resource-group resourcename --name code-server --exec-command "ls" it is giving list of files and folder but if we run az container exec --resource-group resourcename --name code-server --exec-command "cd folder" not working showing error like rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"cd Angular\": executable file not found in $PATH"
It's a common issue when you want to execute the commands inside the container instance. This feature does not absolutely support on Azure Container Instance. It only supports the single command and it shows here:
Azure Container Instances currently supports launching a single
process with az container exec, and you cannot pass command arguments.
For example, you cannot chain commands like in sh -c "echo FOO && echo
BAR", or execute echo FOO.
Maybe I do not understand the concept of Azure Container Instances (ACI) and Azure at all correctly. I am using Azure CLI on my Windows-Computer and want to create a Windows-container (core-image) with dockerfile. But there is no AZ command available. I am able to create a container, there is no problem. But not with a dockerfile. Is there a possibility to run docker commands for Azure (Azure CLI, Azure bash, Azure powershell)? Maybe somebody can clarify my misunderstanding.
Many thanks in advance, J.
Of curse, yes, you can use the Azure CLI command to build containers with Dockerfile. But there is a queue for the steps.
The docker image is the first step, you can use the CLI command az acr build to build the image directly in the ACR, with your Dockerfile. For example, the Dockerfile is in your local machine and it's windows image:
az acr build -t sample/hello-world:{{.Run.ID}} -r MyRegistry . --platform windows
The ACI is the second step, CLI command az container create will help you to create the container instance with your images. The example command here:
az container create -g MyResourceGroup --name mywinapp --image winappimage:latest --os-type Windows --cpu 2 --memory 3.5
Once you have your image, you should publish it to Azure Container Registry or Docker Hub.
Take a look on the following links, it provides the information to:
Create a container image for deployment to Azure Container Instances
Deploy the container from Azure Container Registry
Deploy your application
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-prepare-app
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-prepare-acr
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-deploy-app
I have recently done the same thing. I have deployed my windows service to Azure Container Instance through Azure Container Registry. Here is step by step process you need to follow. Before performing these steps you need to have published folder of application. You need to install Docker Desktop in your machine.
Create Dockerfile with below commands and put it inside published folder:
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019
COPY . .
ENTRYPOINT Application.exe
Here you need to use base file as per your neeed. You can find Windows base images [here][1]
Now navigate to this directory(published folder path) in Powershell and execute below command:
docker image build -t IMAGE_NAME:TAG . -- name of the image with tag
docker run --rm IMAGE_NAME:TAG -- you can run it locally
Now to push this image to Azure, below are the commands. First login into azure and then azure container registery.
az login -- it will navigate to browser for login
docker login ACR_LOGIN_SERVER_NAME -u ACR_USERNAME --password ACR_PASSWORD
docker tag IMAGE_NAME:TAG ACR_LOGIN_SERVER_NAME/IMAGE_NAME:TAG -- tag local image to azure inside ACR
docker push ACR_LOGIN_SERVER_NAME/IMAGE_NAME:TAG -- push image to ACR
Once you have pushed docker image to ACR, you can see it under Repositories in ACR. Based on this repository, you need to create Azure Container Instance to run your docker image.
To create ACI, click on "Create a resource" and select Containers > Container Instances. Here, you need to key some info like resource group and docker image credentials. Make sure you select Private as Image type and key image registry credentials. This ACI deployment process may take couple of minutes as it will fetch the docker image and then deploy. Once deployment is done, you will see Container running and you can check logs as well.
Hope it helps!!
I've been struggling far longer than I should have on this and I'm sure I must be doing something the hard way.
Basically all I want to do is run a docker image in azure (the eos-dev blockchain image). I've gone through and created the container registry, enabled admin control and created the container using:
az container create --resource-group docker --name eosnode --image xxx.azurecr.io/eos-dev --cpu 1 --memory 14 --ip-address public --ports 80 7777 5555 --registry-password "zzz"
Now if this was a local docker instance id simply be able to run:
docker network create testnetwork
And I would get this back:
77af2f92d66895bbf71490b33d775a116d6d8d7be0cbd0a2b3d18ce7336cf611
Now, I'm attempting to do it on the remote azure container like this:
az container exec -g docker --name eosnode --container-name eosnode --exec-command "docker network create testnetwork"
But it returns nothing and I have no idea if it even did anything. What am I missing here?
As you say, you just want to run a docker image in Azure. And I see you create the container instance with the command:
az container create --resource-group docker --name eosnode --image xxx.azurecr.io/eos-dev --cpu 1 --memory 14 --ip-address public --ports 80 7777 5555 --registry-password "zzz"
For this step, the container instance is created in Azure. And you can get the instance information through the command az container show or get logs of the instance with the command az container log.
Also, you can execute the command inside the container instance using the command like this:
az container exec -g resrouceGroup -n instanceName "bash command"
But if you want to run the command docker network create testnetwork inside the container instance, you should install the docker inside the image which you create the container instance from.
docker network create
creates a docker network on the machine/host, the hash code returned is the id of the network. All 'docker' commands suppose to run on the host instead of in container.
Docker network is not necessary to run container in Azure Container instance.
If a container image requires a command to start, usually the command can be found in its document/example with:
docker run <image> <command>
The equivalent way to run the container in azure container instance is:
az container create -g <resourceGroup> -n <name> --image <image> --command-line <command> --restart-policy <Always|OnFailure|Never>
--command-line: specify the command to run in the container
--restart-policy: Define the behavior when the command exit.
I'm still new to the Azure Container Instance scene. I have managed to complete the container instance tutorial. However, I've noticed that the tutorial does not show the reader how to stop a running container instance. The nearest command that gaurantees the container instance is indeed stopped / terminated, is by deleting the Resource Group which created the container.
az group delete -n <ResourceGroupNameThatCreatedContainerInstance>
Is this the correct approach?
The Azure CLI updated and now its possible.
Stop
az container stop --name
--resource-group
[--subscription]
Restart
az container restart --name
--resource-group
[--subscription]
You can use az container delete
az container delete -g MyResourceGroup --name mynginx