本文介绍了尝试在 Windows 2016 Core 容器中创建计划任务时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个包含自定义计划任务的容器.这是我的 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):任务:

在附加到正在运行的默认 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.

推荐答案

问题与 Container 用户有关.默认情况下,使用当前用户创建计划任务.容器用户可能是计划任务命令无法解析为 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 容器中创建计划任务时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 03:40