Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 891
yossiz74 Avatar asked Feb 07 '17 08:02

yossiz74


People also ask

Is Docker compatible with Windows Server 2016?

Docker Enterprise Edition is supported for use with Enterprise Server only on Windows Server 2016 so if you are using Windows 10 you must install Docker Desktop.

Do Windows containers require Hyper-V?

You can run Windows containers with or without Hyper-V isolation.

Can you run containers on a 64 bit Windows 10 enterprise computer?

Starting with the Windows 10 Update, IT can run Docker containers on 64-bit Professional or Enterprise editions of Windows 10 without having to deploy Docker Toolbox. Docker is an open source software platform IT can use to create and manage containers.


1 Answers

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';
like image 182
Rubanov Avatar answered Sep 29 '22 00:09

Rubanov