Search code examples
azurecontainers

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


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.


Solution

  • 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"