python - Docker 映像中的日期、时间和时区错误。无法设置
问题描述
以下是我的 dockerFile。
FROM python:3.8
LABEL version="0.1"
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["sh", "-c", "python3 run_scheduler.py "]
我确实设法更改了 time_zone,但日期和时间仍然是错误的。它显示日期时间为 020-06-11 12:10:37.595709, tz:Etc/UT。我需要 tz 作为 America\New_York。
解决方案
You can set the respective timezone by creating a link of /etc/timezone
and /etc/localtime
to point to necessary timezone file file.
In your case, point the link to /usr/share/zoneinfo/America/New_York
.
You can create the link as a part of Docker build or you can even mount it while running the container.
Setup TZ during build:
FROM python:3.8
LABEL version="0.1"
WORKDIR /app
COPY . /app
RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/timezone && \
ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime && \
pip install -r requirements.txt
CMD ["sh", "-c", "python3 run_scheduler.py "]
Mount timezone while running container:
docker run --rm -it -v /usr/share/zoneinfo/America/New_York:/etc/timezone:ro -v /usr/share/zoneinfo/America/New_York:/etc/localtime:ro <image_name>
推荐阅读
- javascript - DRY:如何将这个重复的日期代码简化为一个函数?
- android - 我们如何识别使用 NDK 构建的库是否支持 64 位?
- javascript - Formik - 如何在提交验证失败时显示附加错误消息
- php - php运行c++编程出现分段错误
- hadoop - 使用 distcp 在 hadoop 集群之间复制数据时出现 DuplicateFileException(记录会导致重复)
- android - onClickListener 不适用于卡片视图上的选项卡式布局
- spring - 非 Spring 安全过滤器的相对排序(如 addFilterAfter、addFilterBefore)?
- typescript - TS2304:找不到名称
- java - 更新 JButton 的背景颜色的问题
- android - 有时一个信号将 UserId 返回为 null