Run interactive Powershell in Windows Azure Container Instance - azure

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.

Related

How to log into container in Azure?

I deploy a docker image inside Azure Container Instance. The application itself will write some log into the file. Is there some way I can log into the container to view these logs?
az container exec --resource-group <group-name> --name <container-group-name> --exec-command "<command>"
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-exec
You could also create a context with docker and then use docker commands.
docker context create aci myacicontext
docker context use myacicontext
docker logs <CONTAINER_ID>
docker exec -t <CONTAINER_ID> COMMAND
https://docs.docker.com/cloud/aci-integration/#create-an-aci-context
Have found the answer.
az container logs --name your-container-name --resource-group your-resource-group-name
or
az container exec --name your-container-name --resource-group your-resource-group-name --exec-command "cat /home/yourname/xxx.log"

docker inspect killed container in az cli

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?

Running commands in azure container instance after container running

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.

Connecting to a jenkins container running on azure

I'm currently running jenkins from a container on my azure container instances, but I'm having difficulty with connecting. I specified port 80 when I run the CLI command:
az container create -g MyResourceGroup --name MyName --image MyImage --ports 80
Is there something I missed or another way I could configure it from the portal so that I can connect and setup jenkins? Any help would be appreciated.
The possible reason is that your container instance is not accessible outside because you do not expose it to the Internet. If you want to expose it to the Internet, the command should be like this:
az container create -g MyResourceGroup --name MyName --image MyImage --ports 80 --ip-address Public
For more details, see parameter --ip-address in az container create.
Or you can connect into the container instance through the CLI command az container exec -g MyResourceGroup --name mynginx --container-name nginx --exec-command "/bin/bash" or exec the command in the portal.
In addition, it seems you run Jenkins in the container instance. I would not recommend you do this. Because the Container Instance is a light-weight service, if you run a server in it, then it won't be actually what it should be anymore. The VM is an appropriate host for the Jenkins server. See Jenkins in VM.
Did you specify the DNS name with the parameter --dns-name-label

Running docker commands in an Azure container

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.

Resources