1

I am trying to build a nanoserver image which includes task scheduling in the dockerfile:

FROM mcr.microsoft.com/windows/nanoserver:20H2  
USER ContainerAdministrator
RUN schtasks /create /tn test /tr test /sc weekly /d MON /st 00:00 /ru system
ENTRYPOINT cmd

When I try to build the image, I get the following result:

Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM mcr.microsoft.com/windows/nanoserver:20H2
 ---> 32f64a4e8b69
Step 2/4 : USER ContainerAdministrator
 ---> Running in 63300b150890
Removing intermediate container 63300b150890
 ---> 347e5db0e75e
Step 3/4 : RUN schtasks /create /tn test /tr test /sc weekly /d MON /st 00:00 /ru system
 ---> Running in 0de9e3866ffb
ERROR: Class not registered
The command 'cmd /S /C schtasks /create /tn test /tr test /sc weekly /d MON /st 00:00 /ru system' returned a non-zero code: 1

However, when I run the same schtasks command in a container using the same nanoserver image it succeeds.

Does anyone know why the command fails in dockerfile but works in the container command line? Does anyone have a solution to that problem?

Thanks you in advance

vcattin
  • 687
  • 1
  • 4
  • 15
  • 2
    Hey @vcattin, Thanks man! I was struggling to schedule a task on nanoserver. Your question helped with missing option. – Ganesh Shinde Dec 12 '22 at 18:18

1 Answers1

0

Another workaround, create a bat script, say test.bat and put below in it.

schtasks /create /tn test /tr test /sc weekly /d MON /st 00:00 /ru system

Do CMD ["test.bat"] at the end of dockerfile. This worked for me.

Ganesh Shinde
  • 65
  • 2
  • 7