How do I run multiple commands when deploying a container group? - azure

I am deploying a Container group with the template https://learn.microsoft.com/en-us/azure/templates/microsoft.containerinstance/2018-10-01/containergroups
It has command parameter, but it is just a string and runs one command. I would like to run multiple commands when deploying. Is it possible?
If not, is there a way to run those commands to the container after it has been deployed, using PowerShell?
My usecase:
I need a SFTP server in Azure for customers to be able to send us data. I then poll that with a Logic App.
What I have done:
I found this template to be good for my needs, as it is easier to poll Azure Storage File Share.
https://github.com/Azure/azure-quickstart-templates/blob/master/201-aci-sftp-files
My problem is I have multiple users. Everyone needs their own username/password and their own file share or sub-directory in that share. I also can't understand how to configure multiple users through the environment variable. I tried separating them with ;. It deploys, but the server doesn't respond to requests at all.
I can deploy multiple containers, one for each user, but that doesn't sound like a good idea when the number of customers rises.

Unfortunately, it seems that you cannot run multi-command in one time. See the Restrictions of the exec command for ACI:
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.
I suggest that you can run the command to create an interactive session with the container instance to execute command continuously after you create the ACI.
For Linux:
az container exec -g groupName -n containerName --exec-command "/bin/bash"
For Windows:
az container exec -g groupName -n containerName --exec-command "cmd.exe"

Related

What all POST Rest API commands we can execute inside a azure container instance

I have build a docker linux image which includes azure cli, kubectl and terraform installation. I have pushed the image to azure container registry and created a container instance manually with that image. My container is running successfully and I am able to connect to it from the azure portal.
But my requirement is, I have to run some Rest API commands which is provided by the microsoft to perform certain action on the container. I have followed below microsoft documentation for executing the rest api command.
Link: https://learn.microsoft.com/en-us/rest/api/container-instances/containers/execute-command#code-try-0
I just provided my container details and added body as below:
{
"command": "/bin/bash",
"terminalSize": {
"rows": 12,
"cols": 12
}
}
I have received 200 response after running the above command. But when I tried running some different commands I am getting the 200 response but output is not changing. Can someone please share the information like what commands I can execute in azure container instance through the rest api.
Actually, this REST API is for the exec command that executes the bash command in the container. So it will create a socket session to communicate with the container, the returns are the socket session and the password.
And for the exec command, also for this REST API, it only can execute the single command, like ls, /bin/bash. But if you want to execute multiple commands like ls -al or curl $url, then it will fail. Actually, ACI does not support running multiple commands through the REST API or the exec command. The solution is you use the Azure CLI command az container exec to run the bash command /bin/bash, it will create a socket session for you, like an SSH connection. Then you can run commands inside the container. Here is the screenshot:

Azure container instance run bash command

I am running an R Shiny app inside a container in Azure Container Instance. Via a DevOps pipeline whenever I change the source code of my App, I recreate the container in the Build pipeline and update the Container Instance via an Azure Cli command in the Release pipline via az container create and az container restart.
After spinning it up I need to run a bash command - namely, automatically adjusting a file within the created container.
In local Docker this would be
docker exec {containerName} /bin/bash -c "echo `"var1 = \`"val1`"`" >> /home/shiny/.Renviron"
This means: run a bash command in the container to push some text into the .Renviron file within the container.
Now the Azure Container Instance says you cannot pass command arguments for az container exec: https://learn.microsoft.com/en-us/azure/container-instances/container-instances-exec
How would you then in an automated build/release process in Azure go for building, releasing and configuring a container?
I do not want to set those values within the build pipeline as I want to use the same image for different staging areas setting those values accordingly.
Many thanks in advance for your help.
I am very new to azure container instances, so I may not understand your aims but it seems another way of achieving this:
I do not want to set those values within the build pipeline as I want
to use the same image for different staging areas setting those values
accordingly.
could be to modify your parameter values upon container creation using the --command-line flag mentioned here. Something like
az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "/bin/sh -c '/path to/myscript.sh val1 val2'"
in which myscript.sh runs your app with the indicated values.

Get the right name of the Container related to an Azure Web App

Is it possible to exec a command in a windows container related to a webapp based on a container? I'm not able to find the right name to use on the cli command az app exec. In fact az container list returns me an empty list. However the container exits cause the web app is running. Where can I find the right name to use with az app exec command? I also checked with the name of only one slot in the webapp without success.
The error az app exec returns is:
The Resource 'Microsoft.ContainerInstance/containerGroups/theNameIPRovide' under resource group 'thegroupNameIProvide' was not found.
Unfortunately, there is no Azure CLI command for Web app for Container to exec the command inside the container. But you can use other ways, for example, the API.
There is no CLI command like az app exec. And az container is for ACI, not for the Web App. You can get all CLI command for Web App in az webapp.
Or you can deploy your application in Azure Container Instance, it also can run windows container for you. So that you can use the CLI command az container exec to execute the command inside your application.
Could you have a look at this https://learn.microsoft.com/en-us/cli/azure/container?view=azure-cli-latest#az-container-exec, Couldnt comment, so had to post it in an answer

Are Azure container instances made for running simple command with simple output?

i am trying to make use of Azure Instances and i need some explanation about the service itself.
I want to use ACI to launch the docker running a command prompting the output of the command and stop the docker.
Is ACI the good service for that kind of things ?
The Docker file look like this.
FROM alpine
RUN apk add ffmpeg
CMD ffprobe -show_streams -show_format -loglevel warning -v quiet -print_format json /input.video
The docker run command to make it work look like this
docker run --name ffprobe-docker -i -v /path/test.ts:/input.video --rm 72e84b2825af
The issue ?
I am not able to launch my script like i can make it work on my machine on azure
What i have done?
I created a private registery where i uploaded my Image.
I ran az container createcommand witch created the ressource
Now i don't know what to do next in order to make it work as expected?
because the container is terminated and the az container exec --exec-command is not showing anything on the terminal once the command is ended.
For ACI, you can create it from your own Docker image in the ACR or other Registries. You can also run the command in it. But you should pay attention to that you cannot run the Docker command in it, because you can not nest container in it. It cannot be a Docker server. It just can be a container.
If you use the CLI command az container exec --exec-command then it will like this:
And the command as the --exec-command parameter should a bash command that can run in your Docker image.
I think the biggest advantage of ACI is the fastest and simplest, and without having to manage any virtual machines and without having to adopt a higher-level service.
Hope this will help you. Any more question please give me the message.

Download version files from app engine

There is any way to download a file from google managed VM docker?
we lost one that is in production version and I want to download it to my computer but I cant find the app path
It should be possible.
First, determine the GCE instance that runs your version. The name of the version should be part of the instance name. If your version has multiple instances, you may have to try all of them (or if your file was part of the application, any of them may work).
From the Cloud console, you can switch it from "Google managed" to self-managed.
Next, use gcloud compute ssh <instance name> to ssh to the instance.
Next, run docker ps to find the container running your application code. You should see a few side-car containers like nginx, but if you look through the names of the containers you should see one for your application.
Finally, you could docker exec -it <container id> -- bash to create a shell on the instance. Or instead of bash, perhaps run a cat command or whatever else you need to do to recover your file.

Resources