-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
TZ environment variable from image overwrites timezone defined in containers.conf #24191
Comments
This works as designed. The config option does not set a timezone variable at all, instead it creates the proper /etc/localtime symlink in the container or if there is no tzdata in the container copies the file from the host. So that does not effect the environment variable in any way so if the image sets its own TZ env this must be passed into the container unless overwritten or unset ( I don't think it is a good idea to suddenly overwrite a env from the image when a timezone is specified, if the image is hard coding this env it may have a reason for that and if we now suddenly start changing the behavior it may break others. I do agree that it may not be want most users want but I think if the env var is a concern that the default env should be set in containers.conf too rather than adding special logic to podman for the env var as well. In any case I do not consider this a bug |
@Luap99 Thanks for your support 👍
And that exactly is the issue. It is not possible to overwrite TZ using the env key in containers.conf if the TZ variable is defined in the container image. Maybe a section to overwrite environment variables in containers.conf is an option e.g containers.env_overwrite ? |
That sounds like a bug, user specified env should always overwrite the image env unless I am overlooking something here. |
@mheon Do you know why this is? podman/pkg/specgen/generate/container.go Lines 127 to 136 in 6b0ad82
Basically what I think it comes down to is there is the actual default env |
Not my code originally so I can't say for sure. My understanding of precedence was Default vars < Image vars < User-added vars. Is this implying that images don't override the defaults, only get added when a variable with that name doesn't exist? |
That is what we do but does that make sense? This example here clearly shows there is a need for a generic env overwrite for images and in my head I always assumed Image vars < config defaults < user-added. I guess the $PATH example is the one thing were we like the current way but otherwise I think config default should overwrite images IMO. Given this can both ways the suggestion of a new env_overwrite field is likely the best way forward if we do not want to alter the existing behavior. |
Using image-provided over defaults always seemed to make sense, but $PATH and $TZ do seem to be exceptions and there may be others. I do not want to change current behavior as it seems generally correct, but having a way to specify a default should be used instead makes sense. Probably a real pain code-wise, though, we don't have a consistent place where all the defaults are added (e.g. a lot of things like |
I think it is best to use env_override as a new containers.conf entry to override Image defaults. The way containers.conf was designed was BuiltinDefaults Env -> Containers.conf Env overrides -> Image Env -> User --env* Overrides Thinking in the most case Image understands best. With PATH being the best example of this. BuiltinDefaults Env -> Containers.conf Env overrides -> Image Env -> Containers.conf EnvOverrides -> User --env* Overrides Where last one wins. |
A friendly reminder that this issue had no activity for 30 days. |
Issue Description
I think it is bad practise to set the timezone in a container image by using the the
TZ
variable.But some image define it nevertheless.
A timezone defined in /etc/containers/containers.conf will be overwritten by the
TZ
variable in the image,which is not what I expect. I can overwrite the TZ variable by passing
--env TZ=:/etc/localtime
to podman.But this must be done for every container.
Idea
When a timezone is defined in /etc/containers/containers.conf and the image defines a TZ environment variable,
then either clear it or overwrite it with
TZ=:/etc/localtime
unless a specific timezone is passedas environment variable with
--env TZ=Somewhere
See also https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
Steps to reproduce the issue
Dockerfile for test image
timezone configuration in /etc/containers/containers.conf
Describe the results you received
PDT
Timezone is set to America/Los_Angeles
Describe the results you expected
CEST
Timezone is set to "Europe/Berlin" as defined in /etc/containers/containers.conf
podman info output
version:
APIVersion: 5.2.2
Built: 1726479282
BuiltTime: Mon Sep 16 09:34:42 2024
GitCommit: ""
GoVersion: go1.23.1
Os: linux
OsArch: linux/amd64
Version: 5.2.2
Podman in a container
No
Privileged Or Rootless
None
Upstream Latest Release
Yes
Additional environment details
Additional environment details
Additional information
Additional information like issue happens only occasionally or issue happens with a particular architecture or on a particular setting
The text was updated successfully, but these errors were encountered: