Can I change the date and time in a Windows Docker Container?
Asked Answered
N

1

2

I am trying to test a software that exports a file in certain periods of time. I thought of using a docker container to give the desired time and not use system time. The thing is that I am lacking permissions to change the containers time with the following error message.

PS C:\usr\src\app> Set-Date -Date (Get-Date).AddDays(3)
Set-Date : A required privilege is not held by the client
At line:1 char:1

Is it possible to do on a windows docker container? My base image is mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019

Thank you in advance!

Naoma answered 24/7, 2020 at 8:46 Comment(0)
K
0

What I suspect you are running into here, is that recent windows container versions now set the user as a normal user, not an admin, so when the container is running your user context does not have permission to modify the system date.

You should be able to get around this, by modifying your Dockerfile, to tell it to use the admin user instead like so:

USER ContainerAdministrator

Keep in mind of course, that this does increase the security risks, as now all processes are run as admin, but if you are only using the container locally (not running a web server or anything) you should be fine.

Kierkegaard answered 28/7, 2020 at 11:15 Comment(1)
Thank you for the reply! Currently it seems that I am the User ContainerAdministrator C:\usr\src\app>whoami user manager\containeradministratorNaoma

© 2022 - 2024 — McMap. All rights reserved.