-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuring time zone #284
Comments
@senarvi thanks for this post, I also recently noticed the same issue. I temporarily fixed it by adding the timezone manually to each container in But your suggestion seems the best one! |
I didn't know about docker-compose.override.yml. That can also be used to modify the configuration without having to modify |
You can't simply add TZ to every container's definition (regardless of which method you use) and expect it to "just work". A container actually has to support it. I've experimented with this before without getting anywhere but @877dev raising the matter on Discord made me start thinking about it again and I may've stumbled across the magic incantation. I'm currently playing with AdGuard Home. It doesn't respect TZ so it's a good test container. What's my Raspberry Pi's time zone?
At the moment, this is UTC+11. What time does my RPi think it is?
The work-in-progress service definition:
Bring it up.
Does the container receive the TZ environment variable?
You betcha! What time does the container think it is?
UTC. 😢 Now for the magic incantation:
What does the container think the time is now?
😀 We're cookin' with renewables (gas being so passé). It seems that that is all there is to it, at least for images built on top of Alpine. The problem we face is implementing this. If we want to do it at the IOTstack level, we need to use Dockerfiles like we're doing for NodeRed. That creates problems of its own for users who find it difficult to understand that different approaches are needed to update images we use "as is" from DockerHub vs those where Dockerfiles are involved. One step removed is trying to convince the upstream image provider (in this example that would be the AdGuard Home team) to add tzdata to their image. Probably do-able but it could easily become a bit of an albatross if IOTstack committed to trying to make sure every container respected TZ. One step further removed again is trying to convince the base image providers (in this example that'd be Alpine) to do it there. I don't think that would wrong-foot any downstream user of the image who had already done it but the starting position with these base images seems to be a combination of "bare minimum" plus "no unnecessary changes" so I wouldn't hold my breath. If anyone has any ideas on how we might go about this, I'm all ears! |
Err, hold the phone. I'm currently also building Mosquitto from a Dockerfile (long story). I added TZ to the service definition and tzdata to the local image but - nada. More investigation needed. |
I tried lots of things with Mosquitto but had zero success in getting it to behave. Of the containers I'm running, the following respect TZ:
I didn't have any luck with Mosquitto or NextCloud.
|
Excellent work, quite interesting how it works. So it does not actually hurt to declare the TZ variable, it's just not used in unsupported containers. As I just swapped back to IOTstack old menu, there are references to You can add these to the list that respect TZ:
Mosquitto does not respect TZ for me either:
Portainer CE really does not like it:
|
I honestly don't know what plane of existence Portainer's designers inhabit but their decision to remove pretty much everything from the container mystifies me. Still, I've never seen the point of Portainer. For a long time I hoped I'd have the "ahah" moment but I've given up on that. Yes, you can create any old environment variable you like. Docker will transport any variable you define into the container. It the container respects the variable, it will take action. If it doesn't know about the variable, it ignores it. Environment variables are just "there". No syntax checking. No spelling checking. No validation. They either work or they don't. One odd thing I did notice yesterday was one container where I had an environment file but I added "environment" plus TZ to docker-compose.yml. That didn't work. No error. Just didn't work. When I stopped being lazy and moved the TZ into the environment file, it worked. I had been assuming you could mix and match. I've yet to check the compose-file doco and re-test so I'm 100% sure but, right now, I'd say "don't use both". That said, it's on my to-do list to migrate all my env-files into environment directives in docker-compose.yml. I do think that's a useful improvement from new menu - even though I can't abide some other things from new menu like the explosion of networks. I think getting Mosquitto to respect TZ will need the maintainer to undo whatever it is that he has done to break it in the first place. I've stared at the Dockerfile until my eyes have gone square but I can't spot it. |
Well, hang up the phone, switch carriers, re-dial, and hold the phone again. The compose spec says that anything in an Testing also confirms a fragment can have both a list of variables under an It also doesn't matter what order the Now, consider these:
Guess what? The quoted form does not work. Even though it should not matter (in theory), it does in practice. It has to do with how the variable is used under the hood: Assume the following in InfluxDB's fragment in docker-compose.yml:
We UP the container and then open a shell into the container. First step is to prove that the variables are being transported into the container (remembering that in what follows the "#" is the root user's prompt, not a comment):
Let's construct the paths that are used to set up timezones:
I'm sure you can see where this is heading...
That's the problem. But wait, there's more!
That's all there was to it. Dang'd quotes! 🤬 We can add Mosquitto to the list in the "providing tzdata is added" column. I will now fetch a two-by-four and beat myself over the head. |
I managed to set the timezone with TZ to every service that I use, where it makes a visible change to the user, i.e. in the UI. Is the wrong date in e.g. mosquitto actually a problem? |
I submitted a Pull Request for AdGuard Home to add The answer to your question is "yes and no". At the technical level, no. Unless someone does something seriously silly, all modern systems run on UTC internally. You could argue that timezone correction only matters to human viewers and even then it isn't really all that hard to add or subtract your offset from UTC. The "get over it" argument. That said, a container displaying UTC can surprise users who don't understand that it's all UTC under the hood, to the point where they think something must be wrong. That is, after all, sort of how we got here, isn't it? A UTC display can also occasionally be misleading. You run a I'm also sure you're aware of having looked at something like a log entry then glanced at the time-of-day clock on your screen/wrist/wall to make an instant mental assessment of "how long ago?" and "is the difference reasonable?". Those calculations are made much harder if the container is displaying UTC, especially if it's close to the top of the hour. Plus, the very time you start looking at logs is when something stopped working. The recent unilateral changes (see Read this if your Mosquitto is broken) is a case in point. You're in a panic. The log is the only thing you have to go on. That's really not the right time to be considering whether it's the right time (awful pun intended). So, on balance, I'd say we're building for humans so we should accommodate human needs and implement TZ where we can. Seeing as I got such a warm reception with AdGuardHome, I might give the Mosquitto people a try. They make things a bit harder than most repos; some nonsense about signing an agreement before you're allowed to contribute. I'm not into hoop-jumping of that kind (life's too short) but an issue pointing out that simply adding tzdata would do the trick might get me over the line. |
Right, at least it affects the timestamps in the logs. Great work! |
Yes I found that to be the case too!
Go easy with the two by four ! :) |
Mosquitto was fixed a while back to add tzdata via Dockerfile. Most of the rest of this is either fixed or obsolete but the basic idea of |
I'd suggest
|
Many services display time incorrectly, unless the local time zone is configured by setting the TZ environment variable. Some of the
service.yml
files in IOTstack set the TZ environment variable to Etc/UTC, Europe/Paris, or Europe/Berlin - wherever the person is living who contributed that service.Docker Compose supports substituting environment variables in Compose files. We could instead use the following in
service.yml
:And the user could configure time zone by setting the TZ environment variable, or creating a file
.env
in the IOTstack directory that contains something like:The text was updated successfully, but these errors were encountered: