docker Selenium网格容器-设置时区

mm9b1k5b  于 2023-02-15  发布在  Docker
关注(0)|答案(1)|浏览(166)

如何在运行SeleniumGridDocker容器时设置时区?我尝试过这样做

docker run -d -p 4444:4444 -p 443:443 -v /dev/shm:/dev/shm selenium/standalone-chrome -e TZ=”Europe/Uzhgorod"

但我收到一个错误:

Error response from daemon: failed to create shim: OCI runtime create failed: runc create failed: unable to start container process: exec: "-e": executable file not found in $PATH: unknown.

你能帮我解决这个问题吗?先谢了。

wbrvyc0a

wbrvyc0a1#

由于Selenium Grid容器不包含Tzdata支持环境变量,因此在运行容器时无法设置TZ。我曾尝试在运行容器内进行设置。但是没有效果。所以我决定用不同的方法解决这个问题,在容器中添加两个负责主机系统上时区设置的目录作为卷。我可以看到容器的系统时间被设置为我的时间。但是,无头Chrome仍然继续使用UTC时间。到目前为止,我还没有找到一个解决方案,所以解决这个问题的唯一方法是使用Python脚本功能将UTC转换为基辅时间。
也许这对某些人会有帮助。

import time
import datetime
import re
from datetime import timedelta
    
def text_processor(text):
    #looking for all dates in text using regex
        regex="(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)"
        newtext=text
    # checking the if the summer time is on (The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.)
        if time.localtime().tm_isdst:
            time_correction=3
        else: 
            time_correction=2
    
        for timestamp in re.findall(regex, text):
     #formating timestamp and adding a correction to UTC time
    
            datetime2= (datetime.strptime(timestamp, '%H:%M:%S')+ timedelta(hours=time_correction)).strftime('%H:%M:%S')
            newtext=newtext.replace(timestamp, datetime2)
        
        return newtext

相关问题