tiangolo / uvicorn-gunicorn-fastapi-docker

Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python with performance auto-tuning.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong UTC time?

Vvaltz opened this issue · comments

Using Windows 10, Docker Desktop

In container:
Thu Feb 13 17:49:33 Vilnius 2020
Google says:
Thu Feb 13 18:49:33 Vilnius 2020

Tried:

apt-get update && apt-get install tzdata
ENV TZ=Europe/Vilnius
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

All other containers that use ubuntu images are OK. This is the first I encountered;

Please help ? I'm not too familiar with docker, and this is quite a problem if you ask me

I think you are getting an incorrect timezone, not an incorrect UTC time.

Hmm, whenever you deploy your container it will probably be in a datacenter that might be in a different timezone different than yours, so I'm not sure how useful it would be to assume a timezone in your container.

It would probably be better to use UTC in your code. Or if you are going to depend on timezones, it should be the timezones of your clients or timezones defined in your settings.

For example with things like:

from datetime import datetime

now = datetime.utcnow()
print(now)

Otherwise, please provide more info and a minimal self-contained example that shows the error.

Currently, I have no way of knowing how you are getting those dates, or how to help you debug it.

Sorry for the late response. Turns out it was an issue with Docker for Windows:
docker/for-win#4526
The clock would drift when the host machine went into rest mode. Sorry for taking your time.
It was just a coincidence I was trying to do something time-specific with these containers.

Cool! Thanks for reporting back and closing the issue 👍