Conversation
|
I'm a bit torn on this one, mostly because of not wanting to change things that currently work as intended. I would definitely think this is something to include in a v3, yes. One big question in here would be: considering this would be merged and users that currently mount their TZ data as it's done right now updated without changing their config, would their setups still continue to work? |
|
I just tested it by using my custom image (only adding environment:
- TZ=${TZ}
image: offen/docker-volume-backup:v2.47.2-tzdata-test
volumes:
# - /etc/timezone:/etc/timezone:ro
# - /etc/localtime:/etc/localtime:ro
# - /usr/share/zoneinfo:/usr/share/zoneinfo:roI also tried the custom image with environment:
# - TZ=${TZ}
image: offen/docker-volume-backup:v2.47.2-tzdata-test
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- /usr/share/zoneinfo:/usr/share/zoneinfo:roI then tried using the custom environment:
- TZ=${TZ}
image: offen/docker-volume-backup:v2.47.2-tzdata-test
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- /usr/share/zoneinfo:/usr/share/zoneinfo:roAll cases are working as expected, producing the expected time with the Perhaps it is better saved for v3, but I think this functionality could be enabled without issue immediately. |
|
From #28 (comment) /usr/share/zoneinfo:/usr/share/zoneinfo:roPage it's missing from: set container timezone services:
backup:
image: offen/docker-volume-backup:v2
volumes:
- data:/backup/my-app-backup:ro
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
volumes:
data:I can edit and open a PR to fix |
That'd be grand 🎩 |
|
Continuing our conversation here...
No worries. I can do some more testing and report back. I was doing some research on ChatGPT and it agrees that it's a low-risk change. I think the testing I did above will cover users that upgrade to a new image that includes |
|
Id like to throw my hat in the ring for this addition to the codebase. The current way of binding the OS host timezone did work for me as intended, but it feels a bit awkward as I am depending on an upstream config of my host system. Which could change. Being able to set the time zone explicitly (and also in only 1 line) would feel like a great ease of life feature. one question that comes to mind: Also, if this is added, it would be great if the time zone would be logged on startup (“Timezone set to “Europe/Berlin via environment variable.”) I also feel that the very slim increase in image size is worth it. |
@le-lenn great question. In short, if both are set, the timezone set by the env variable TZ (used by the
For configurations 2 and 3, I am using an image created with the following Dockerfile: FROM offen/docker-volume-backup:v2.47.2
RUN apk add tzdata curl jq --no-cacheConfiguration 1: environment:
# - TZ=America/Los_Angeles
image: offen/docker-volume-backup:v2.47.2
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- /usr/share/zoneinfo:/usr/share/zoneinfo:roConfiguration 2: environment:
# - TZ=America/Los_Angeles
image: offen/docker-volume-backup:v2.47.2-tzdata-test
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- /usr/share/zoneinfo:/usr/share/zoneinfo:roConfiguration 3: environment:
- TZ=America/Los_Angeles
image: offen/docker-volume-backup:v2.47.2-tzdata-test
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- /usr/share/zoneinfo:/usr/share/zoneinfo:roConfiguration 1 represents users today, and configuration 2 represents a new image with Configuration 3 shows that when I would argue that there is no need to print the current timezone upon container start, it is UTC by default. If a user modifies it from the default, they should know what they are updating it to. Worst case users can run the I like your point about the dependency created by the upstream host. The Let me know if there's anything I can clarify. |
|
I guess it makes sense to do this, yes. A few more remarks from my end:
|
|
My line of thinking with printing the configured time zone on startup was to have a way to catch accidental misconfigurations and warn the user about it. |
|
@le-lenn the time zone defaults (without warning) to UTC if you do not provide a valid tz database time zone @m90 we should be able to add a script that does something similar to the following: A possible script could look something like this: #!/bin/sh
# List of deprecated bind-mount targets
DEPRECATED_MOUNTS="/etc/timezone /etc/localtime /usr/share/zoneinfo"
FOUND_DEPRECATED=false
for mnt in $DEPRECATED_MOUNTS; do
# Check if the path is explicitly listed as a mount point
if grep -q " $mnt " /proc/self/mountinfo; then
echo "WARNING: Bind-mounting '$mnt' is DEPRECATED."
FOUND_DEPRECATED=true
fi
done
if [ "$FOUND_DEPRECATED" = true ]; then
echo "-------------------------------------------------------------------"
echo "Use the 'TZ' environment variable to set the time zone"
echo "Please see the documentation for more details"
echo "-------------------------------------------------------------------"
fi
# Continue to main application
exec /usr/bin/backup -foreground "$@"This script would become the new entrypoint in the Dockerfile, and it could then call your current entrypoint. I will test this out. |
Changes
tzdatapackage to Docker imageReason
Installing
tzdataprovides the system timezone database and allows the container timezone to be configured via theTZenvironment variable.