我可以在Windows Docker容器中更改日期和时间吗? [英] Can I change the date and time in a Windows Docker Container?

查看:195
本文介绍了我可以在Windows Docker容器中更改日期和时间吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试在特定时间段内导出文件的软件.我想到了使用docker容器提供所需的时间,而不使用系统时间.事实是,我缺少更改容器时间的权限,并显示以下错误消息.

  PS C:\ usr \ src \ app>Set-Date -Date(Get-Date).AddDays(3)设置日期:客户端未拥有所需的特权在第1行:char:1 

是否可以在Windows docker容器上执行操作?我的基本映像是mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019

提前谢谢!

解决方案

我怀疑您在这里遇到的问题是,最近的Windows容器版本现在将用户设置为普通用户,而不是管理员,因此当容器处于运行用户上下文没有权限修改系统日期.

您应该能够通过修改Dockerfile来解决这个问题,告诉它使用admin用户,就像这样:

USER ContainerAdministrator

请记住,这确实增加了安全风险,因为现在所有进程都以admin身份运行,但是如果您仅在本地使用容器(而不运行Web服务器或其他任何东西),那应该没事./p>

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!

解决方案

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.

这篇关于我可以在Windows Docker容器中更改日期和时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆