Error trying to create a scheduled task within Windows 2016 Core container Error trying to create a scheduled task within Windows 2016 Core container docker docker

Error trying to create a scheduled task within Windows 2016 Core container


The issue has to do with the Container user. By default a scheduled task is created with the current user. It's possible the container user is a special one that the Scheduled Task command cannot parse into XML.

So you have to pass the user /ru (and if needed the password /rp) to the schtasks command in a Windows Container.

This works

FROM microsoft/windowsservercoreRUN schtasks /create /tn "hellotest" /sc daily /tr "echo hello" /ru SYSTEM

It will run the command under the system account.

If you are a fan of Powershell (like me), you can use this

FROM microsoft/windowsservercoreSHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]RUN $action = New-ScheduledTaskAction -Execute 'echo ""Hello World""'; \    $trigger = New-ScheduledTaskTrigger -Daily -At '1AM'; \    Register-ScheduledTask -TaskName 'Testman' -User 'SYSTEM' -Action $action -Trigger $trigger -Description 'Container Scheduled task test';