docker - 为 Windows 容器设置时区

标签 docker powershell windows-server-2019 windows-container windows-server-2022

我正在尝试设置基于 windows nano server 2019 Build 1809 的 WindowsContainer 的时区。

为 linux 容器执行此操作的最简单方法之一是设置 TimeZone 环境变量,如下所示:

docker run -e TZ=Asia/Kolkata ubuntu date

对于 Windows 容器,我们是否有类似的东西。基于一般的 Windows 方法,我尝试使用 PowerShell 之类的(如下所示)在入口点脚本中设置它,但它也给了我一个错误。
Set-TimeZone -Name "India Standard Time"
Set-TimeZone : Access is denied
At line:1 char:1
+ Set-TimeZone -Name "India Standard Time"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : FromStdErr: (:) [Set-TimeZone], Win32Exception
+ FullyQualifiedErrorId : SetTimeZoneFailed,Microsoft.PowerShell.Commands.SetTimeZoneCommand

关于如何为基于 Windows Nanoserver 2019 Build 1809 的 Windows 容器完成此操作有任何想法吗?

最佳答案

已编辑:Pierre-Luc Champigny指出,据微软称,现在 ltsc 版本和即将推出的版本都支持此功能:https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/virtual-time-zone

无法在 Windows Server Core 容器上正确设置全局化设置,例如时区、语言或 Windows 位置。

  • tzutil抛出权限不足错误
  • 容器启动时忽略注册表设置

  • 似乎您必须确保容器主机上的时区正确。
    这没有多大意义,AFAIK,关于容器的全部内容是将其作为镜像发送一次并在任何地方运行,使用 环境隔离和完整性 .. 对?!
    不管怎样,你可以看到更多的细节 issue on github .
    另外,我打开了这个 suggestion on Windows Server uservoice ,改变这种行为。
    另外,我打开了这个 feature suggestion for improving Azure AKS host configuration对于时区。

    关于docker - 为 Windows 容器设置时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55514732/

    相关文章:

    docker - 在 Kubernetes 上使用 TCP 连接的 SSL?

    python - 在 $PATH 中找不到 Docker 组合可执行文件": unknown

    amazon-ec2 - Windows Server 2019 上的 Microsoft Store

    PowerShell 管道参数绑定(bind)顺序

    c# - 缺少小数点分隔符

    docker - 在 Windows 2019 服务器上运行 linux 容器时出错

    ruby-on-rails - 无法通过docker启动rails应用程序

    Ubuntu 上的 Docker 无法连接到 localhost

    powershell - Stop-Service Cmdlet无法打开存在的服务

    powershell - 如何在 Powershell 中将元素添加到数组前面?