5

I am trying to build a container which would include a custom scheduled task. This is my dockerfile:

FROM microsoft/windowsservercore
RUN schtasks /create /tn hello /sc daily /st 00:00 /tr "echo hello"

I get the following error:

ERROR: The task XML contains a value which is incorrectly formatted or out of range. (43,4):Task:

I get the same error also when attaching to a running default windows core container and running the command.

Needless to say, the command works well on standard windows 2016 server.

It seems like a bug in Windows containers, but I didn't find any known issue about it.

Appreciate any leads which may help figure out.

2
  • Any luck with this error? I'm also running into this issue
    – texens
    Aug 5, 2017 at 8:26
  • No, i ended up creating the schedule on the hosting OS.
    – yossiz74
    Aug 5, 2017 at 21:39

1 Answer 1

9

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';
2
  • 1
    Spot-on! Thank you!
    – yossiz74
    Oct 9, 2017 at 13:36
  • if you are running schtasks in a container from PS youll probably need to escape stuff: RUN schtasks --% /create /tn "hellotest" /sc minute /mo 30 /ru SYSTEM /tr \"echo lskjflsdf\"
    – red888
    May 21, 2018 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.