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

99封情书 提交于 2019-12-04 07:51:14

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/windowsservercore
RUN 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/windowsservercore

SHELL ["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';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!