Date and time incorrect when used on Raspberry PI

Some recent images don’t seem to be able to show correct date and time when run on a Raspberry PI. For example:

docker run --rm httpd bash -c "date && cat /etc/os-release"
Thu Jan  1 00:00:00 UTC 1970
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
docker run --rm httpd:buster bash -c "date && cat /etc/os-release"
Wed Nov 24 11:03:18 UTC 2021
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
bash -c "docker -v && date && cat /etc/os-release"
Docker version 19.03.15, build 99e3ed8919
Wed 24 Nov 12:04:06 CET 2021
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Hello Paul and welcome :slight_smile:
the difference between the second and third command is (due to different time-zones) only 48 seconds. So this might be fine depending on your typing-speed.
I guess you know that a Raspberry does not have a battery-backed-up clock (as “normal” computers have) - so it needs to fetch the current time from a remote server using NTP. This may take some time until the process is finished and this might be the reason for the invalid time in the first command.
Best regards
Matthias

1 Like

Exactly as @matthiasradde mentioned, the difference is the timezone. You have to deal with the timezones in the applications and in the log messages/log aggregator. You could change the timezone inside the container but I have never done that since it was never necessary for any application.

Just a small interesting fact. The new Linux kernels have time namespace to test some timesyncing issue. Docker doesn’t support it yet as far as I know but I saw a feature request on Github to implement it.

Also, please use the code block button (</>) above the text area when you insert codes. That way you don’t have to edit URLs to avoid converting them to hyperlinks. I edited your comment. If you try to edit again, you can see the difference. Thanks.

@matthiasradde I didn’t know about the missing “battery-backed-up clock” so thanks for that info :slight_smile:

Hi Matthias

Thanks for the reply, but I don’t think this has to do with time-zone. I only noticed a difference when using image httpd (which is latest) and httpd-buster (which is older). So

docker run --rm httpd date
Thu Jan  1 00:00:00 UTC 1970

compared to

docker run --rm httpd:buster date
Wed Nov 24 16:37:22 UTC 2021

Kind regards
Paul

Thanks Akos, I’m new and learning and I modified my post with code block tags :slight_smile:

Of course when the container shows you it’s 1970 that is not a timezone difference. If it always shows you 1970 then you might have some kind of compatibility issue. You have a very similar problem to the following:

Note that the operating systems and versions in the issue on GitHub are different. You have to find the proper libraries.

Updating libseccomp on the host (raspberry pi arm32) solved it.

See Core dumped in sdk:6.0.100-bullseye-slim-arm32v7 and sdk:6.0.100-alpine3.14-arm32v7 without --privileged · Issue #3253 · dotnet/dotnet-docker · GitHub