A p*_*son 3 ubuntu datetime docker dockerfile docker-compose
我有一个 AWS EC2 实例,计划在太平洋标准时间晚上 11:50 打开并在太平洋标准时间晚上 11:59 关闭。我已将实例的时区设置为 MST,以便我可以运行一个 cron 作业,在晚上 11:55 MST 执行 .sh 文件。cron 作业非常简单:55 23 * * * sudo bash docker run --mount type=bind,source="/home/ec2-user/environment/Project",target="/Project" myubuntu. docker 将挂载到本地文件夹“Project”,其中包含一个 .cpp 文件,该文件可以从 Steam 的用户信息页面抓取数据。.cpp 文件中的代码非常依赖于当前时间/日期,因此我花了这么多工作来让所有内容在 MST 中运行,以便一切都是标准的。然而,即使所有东西都在 MST 上运行,当 docker 容器运行时,它并不在 MST 中,尽管 dockerfile 声明要运行 with ENV TZ="America/Salt Lake City",我已经将其从盐湖城更改为凤凰城只是为了尝试一下,但它仍然没有在 MST 中运行 docker。例如,当我在 11 月 24 日 MST 晚上 9:22 运行 docker 时,docker 中的日期是 UTC 11 月 25 日凌晨 04:22。这个轻微的日期和时间变化极大地影响了我尝试运行的代码。
为了解释代码的作用,Steam 有一个 .json URL,其中包含“[unix 纪元时间,登录用户数]”中约 48-62 小时的数据。目标是自动化,所以我想如果我让代码删除任何与代码运行日期不匹配的数据,它就不会包含在数据收集中。因此,我通过在每天结束时运行代码来一次收集 24 小时的数据。我和我的 EC2 实例运行的 MST 时间与我的 Docker 运行的 UTC 时间之间的日期/时间差异导致了数据收集问题。
我的教授给了我 dockerfile,据说它被设置为在 MST 上运行,但据我所知并非如此。我尝试在包含的 .sh 文件中运行我的命令,-v /etc/timezone:/etc/timezone但这似乎也没有解决时区问题。我得到的 dockerfile 如下:
# This image will be based on the ubuntu image. Build it using the
# command in the comment below. You may omit the ubuntu pull if you already
# did it. Before running the build, change into the directory containing
# this Dockerfile.
FROM ubuntu
# Set a default shell.
SHELL ["/bin/bash", "-c"]
# The timezone library stops the docker build and waits for user input to
# select a timezone. This breaks the build. To get around this,
# set up timezone information prior to installing that library. This
# Docker code does that. Composited from two sources:
# https://rtfm.co.ua/en/docker-configure-tzdata-and-timezone-during-build/
# https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ="America/Phoenix"
# Install a handful of useful libraries. Note that this is generally against
# best practices -- containers should be lean, and not include 'things you
# might use'. In our case, we're using the containers for development, so
# this may be reasonable here.
RUN apt-get -y update && apt-get -y install \
apt-utils \
emacs-nox \
g++
# Copy in the files from the current folder (recursively) For our purposes,
# put them in /cs3505
COPY . /cs3505
RUN apt-get -y install wget
Run Code Online (Sandbox Code Playgroud)
我或我的教授在 Docker 设置中是否做错了什么导致了这个时区问题?我该如何修复我的 docker,以便每次在晚上 11:55 MST 运行时,它都会以 MST 作为时区打开?
编辑:我不知道这是否有什么不同,但运行cat /etc/timezone返回“美国/山”并且运行emacs /etc/timezone显示相同的内容。
小智 5
这是我基于Debian定制的一个dockerfile,可以参考\xef\xbc\x9a
\nFROM debian:stable-slim\n\nARG ARG_TIMEZONE=Asia/Shanghai\nENV ENV_TIMEZONE ${ARG_TIMEZONE}\n\n# install base dependence\nRUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \\\n && apt-get update && apt-get install -y -q \\\n dialog apt-utils \\\n locales systemd cron \\\n vim wget curl exuberant-ctags tree \\\n tzdata ntp ntpstat ntpdate \\\n && apt-get clean && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* \\\n && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8\n\n# sync timezone\nRUN echo '$ENV_TIMEZONE' > /etc/timezone \\\n && ln -fsn /usr/share/zoneinfo/$ENV_TIMEZONE /etc/localtime \\\n && dpkg-reconfigure --frontend noninteractive tzdata\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
4385 次 |
| 最近记录: |