问题
I have a multi-container app that I need to run twice a day at specific times for about 30 mins each time. To save costs, I would like to:
- Turn on a Linux VM on Microsoft Azure
- Run a script that runs
docker-compose up -d
, waits 30 mins, then callsdocker-compose stop
- Turn off the VM
I'd love for this to happen automatically on a cron schedule.
So far, I've failed to find any Azure solution that can do all of this. Azure automation allows you to turn on/off VMs but it doesn't allow you to run a sh script on it after you've turned it on. Azure Logic apps allows you to spin up containers on a schedule but not with docker-compose.
Any idea on how I might accomplish this in a way that doesn't involve me having a VM that is always on?
回答1:
No worries , you can use this AZ powershell command to run sh script on your Azure VMs directly via Azure automation runbook with prarm : -CommandId 'RunShellScript'
For AzureRM commands , refer to here
I have tested on my side and it works perfectly for me .
来源:https://stackoverflow.com/questions/59112150/schedule-azure-vm-to-turn-on-run-a-script-and-turn-off