docker-php icon indicating copy to clipboard operation
docker-php copied to clipboard

Improvement of Timezone Handling and Caddy Log Formatting

Open K2ouMais opened this issue 1 month ago • 8 comments

Description:

It has been possible to set container timezones via the TZ environment variable without installing tzdata. To improve visibility and usability, I have explicitly added this ENV variable to all Dockerfiles and updated the documentation.

FrankenPHP & Caddy Logging:

Currently, the FrankenPHP images (using Caddy) output logs in UTC by default, which can complicate debugging. I have adjusted the Caddy configuration to:

  1. Respect the timezone set via the TZ variable in log outputs.
  2. Introduce a new variable, CADDY_LOG_DATETIME_FORMAT, allowing for custom timestamp formats supported by Caddy.

Backward Compatibility:

These changes are fully backward compatible. Default values are in place, ensuring that if TZ or CADDY_LOG_DATETIME_FORMAT are not set, the behavior remains exactly as it is now.

Examples

docker-compose.yml

services:
  app:
    image: serversideup/php:8.5-frankenphp
    environment:
      TZ: Europe/Berlin
      CADDY_LOG_DATETIME_FORMAT: "wall"
...

Running directly in your terminal:

docker run --rm -it \
  -e TZ=Europe/Berlin \
  -e CADDY_LOG_DATETIME_FORMAT=wall \
  serversideup/php:8.5-frankenphp

K2ouMais avatar Nov 27 '25 17:11 K2ouMais

Please take a look at the following file:

https://github.com/serversideup/docker-php/blob/main/src/variations/frankenphp/etc/frankenphp/log-level/global/debug.caddyfile#L1C1-L1C6

There is on line one the word "debug". I just let it the way it was and didnt find any reference in the caddy logs for that. It could be a possible bug?

K2ouMais avatar Nov 28 '25 07:11 K2ouMais

Whoops, I should have commented here 😃

Thanks for opening a PR! I will review for the next release.

Sorry for the delay. I was working on serversideup/php today but I had another bug take many hours longer than expected 🙃

I'll circle back and take a look at this soon.

jaydrogers avatar Dec 05 '25 20:12 jaydrogers

@jaydrogers I made a mistake on this one.

I declared TZ to be available on all images, but that is not true 🤦‍♂️

You can use TZ only on debian based images. On alpine images, tzdata would have to be installed.

Let me know, how should I progress on this one.

K2ouMais avatar Dec 08 '25 15:12 K2ouMais

I reverted recent changes to Dockerfiles that attempted to set the timezone via the TZ environment variable.

Reason for Revert

The TZ environment variable relies on the presence of timezone data, which is not included in Alpine based images. Consequently, this configuration does not work on images built on Alpine.

Impact & New Standard

Alpine Images:

  • Alpine-based images will continue to default to the UTC timezone.

  • Changing the timezone on these images now explicitly requires installing the tzdata package (the standard Alpine method).

  • This typically requires building your own custom image based on the serversideup image and including the tzdata installation step.

  • Caddy logs within these Alpine images will still use UTC timestamps.

Debian Images:

  • The TZ environment variable remains functional for changing the timezone on Debian-based images (which have been the default for some time). This behavior is now explicitly documented.

New Feature for Log Clarity

To improve log readability, especially for users remaining on UTC, we have introduced a new environment variable:

CADDY_LOG_DATETIME_FORMAT: Allows users to customize the timestamp format of the Caddy access logs, providing better clarity and integration with external logging tools.

K2ouMais avatar Dec 10 '25 14:12 K2ouMais

How much space gets added to Alpine if we include tzdata by default?

jaydrogers avatar Dec 10 '25 14:12 jaydrogers

To be honest I didnt try, because you said you didnt want any packages installed, that would possibly make the images bigger, wich is understandable.

K2ouMais avatar Dec 10 '25 15:12 K2ouMais

No problem. I can take a look if needed. I appreciate your efforts on this 👍

jaydrogers avatar Dec 10 '25 15:12 jaydrogers

Please also take a look at this file:

https://github.com/serversideup/docker-php/blob/main/src/variations/frankenphp/etc/frankenphp/log-level/global/debug.caddyfile#L1C1-L1C6

On the first line there is the word debug wich isnt in any other files and I couldnt find anything on the caddy documentation about it. It might be a typo.

K2ouMais avatar Dec 10 '25 15:12 K2ouMais