尝试在Windows 2016 Core容器中创建计划的任务时出错 [英] Error trying to create a scheduled task within Windows 2016 Core container
问题描述
我正在尝试构建一个包含自定义计划任务的容器。
这是我的dockerfile:
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"
我收到以下错误:
错误:任务XML包含格式错误或
超出范围的值。 (43,4):任务:
ERROR: The task XML contains a value which is incorrectly formatted or out of range. (43,4):Task:
在附加到运行的默认Windows核心容器并运行命令时,我也会遇到相同的错误
I get the same error also when attaching to a running default windows core container and running the command.
不用说,该命令在标准Windows 2016服务器上运行良好。
Needless to say, the command works well on standard windows 2016 server.
似乎是一个错误。在Windows容器中,但是我没有发现任何已知的问题。
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.
推荐答案
问题与容器用户有关。默认情况下,将与当前用户一起创建计划任务。容器用户可能是计划任务命令无法解析为XML的特殊用户。
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.
因此,您必须通过用户 / ru
(如果需要,还需要密码 / rp
)到Windows容器中的 schtasks
命令。
So you have to pass the user /ru
(and if needed the password /rp
) to the schtasks
command in a Windows Container.
这有效
FROM microsoft/windowsservercore
RUN schtasks /create /tn "hellotest" /sc daily /tr "echo hello" /ru SYSTEM
它将在系统帐户下运行命令。
It will run the command under the system account.
如果您是Powershell的粉丝(像我一样),则可以使用此
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';
这篇关于尝试在Windows 2016 Core容器中创建计划的任务时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!