feat(docker): 可选注入 TZ 环境变量设置容器时区#1997
Conversation
Added `enableTimezone` and `timezone` properties to the Docker configuration, allowing users to set the container's timezone. Updated relevant files to handle timezone injection into the container environment and added validation in the frontend. Translations for new messages have also been included in multiple languages.
|
容器,特别是Ubuntu容器,单独一个TZ变量可能不够。 |
Updated the Docker configuration to improve timezone handling by allowing the injection of `/etc/localtime` and `/etc/timezone` files when enabled. Added functions for sanitizing timezone names and checking mount targets. Updated relevant translations in multiple languages to reflect these changes.
|
很多简化的环境容器并不自带有时区文件,建议添加/usr/share/zoneinfo的挂载,并且这些挂载尽量以只读模式(ro)进行。 |
Updated the Docker container setup to include the binding of `/usr/share/zoneinfo` alongside `/etc/localtime` and `/etc/timezone` when timezone support is enabled. This change ensures accurate timestamp handling for minimal Debian/Ubuntu images. Additionally, translations in multiple languages have been updated to reflect these enhancements.
|
|
Enhanced the timezone injection process for Docker containers by ensuring the timezone text is written to `/etc/timezone` after container start, in addition to binding `/etc/localtime` and `/usr/share/zoneinfo`. Updated relevant translations in multiple languages to reflect these changes.
…uages Removed redundant timezone-related entries and ensured consistency in the translation of the version detection error message across various language files. This update enhances the clarity and accuracy of the user interface in different locales.
|
从master往你的分支合并一下呢? |
试过,现在其实是这样的(如图是从这个分支往Master合并) 还是不能一键合并,但是如果加在最后一行可能就是乱糟糟的感觉,合并起来难受一点 docker相关PR可能会先被Merge进 |
| ].filter(Boolean) as string[]; | ||
|
|
||
| try { | ||
| this.container = await docker.createContainer(createContainerOptions); |
There was a problem hiding this comment.
此处功能上无问题,但是代码实现上并不是很好,多层 try catch 嵌套和多次重复 await docker.createContainer 不是很好,为了一个时区挂载功能感觉有点过了。
可以尝试将多次尝试抽离到多个函数中,从一个函数作为入口开始调用,如果是时区错误就进入到下一个函数,否则返回,实现代码可读性上的增强。
我能看出来几乎所有代码你都是通过 AI 自动生成,我作为人类静态的去阅读代码难以找出逻辑上的漏洞,估计你自己也不太清楚逻辑是否正确或有无 bug,这方面我希望你能录一个视频或多张截图来提供一个测试结果的保证。

背景/问题
在 Linux 上时区是“内核无关”的配置,Docker 仅共享宿主机内核,因此容器内时区需要在镜像构建或容器启动时单独设置。
目前 MCSManager 启动 Docker 容器时无法便捷地为容器注入
TZ环境变量,导致部分程序/日志时间(CST/本地时间)不正确。变更内容
enableTimezone: 是否启用容器时区注入(默认关闭)timezone: 时区字符串(IANA 时区名,如Asia/Shanghai/UTC)enableTimezone=true且timezone非空时,向容器Env注入TZ=<timezone>docker.env中已有TZ=...,会在启用注入时被覆盖为配置项的值(避免重复/冲突)Asia/Shanghai)Intl.DateTimeFormat().resolvedOptions().timeZone)使用方式
Asia/Shanghai)兼容性说明
docker.env行为(包括手动填写TZ=...也能继续使用)。zoneinfo/tzdata,程序对TZ的支持可能有限;本 PR 仅负责注入环境变量,镜像侧依赖由用户自行保证。测试/验证
关联 Issue
Closes #1087