Unable to change timezone in latest Keycloak 9 docker container


I’ve used Keycloak inside docker in the last couple of years. Now we have started a new project with the latest Keycloak version ( 9.x ) but we can’t figure out why env “TZ=Europe/Rome” doesn’t work anymore.
I’ve tried to search around for some tip but I didn’t find anything.

Any suggestion welcome.

This seems to work just fine here.
Once Keycloak has started it shows the correct date in my logs according to the timezone I’ve set.
The container uses the timezone of the host which is the default.
The TZ environment variable is specific for Keycloak itself, no?
I’m using jboss/keycloak:9.0.0

Thanks for the feedback.

TZ env isn’t specific for Keycloak but for Docker container itself, as far as I know.
This is my default way of setting timezone inside Docker containers.
My host is set with Europe/Rome timezone and not UTC. Docker container shows UTC date.

I’ve used jboss/keycloak:latest. I’ll try with 9.0.0 tag to see if something changes.

@zonaut, you are right. It’s Keycloak env variable. Logs display correct time. Container ignores settings due to immage limitations, but in this case it isn’t important.

Thanks for a suggestion

For anyone encountering this with official jboss/keycloak images:

  • timezone in Keycloak is honored from TZ environment variable
  • timezone outside Keycloak is not honored from TZ environment variable

In order to fix this, add in the Dockerfile:

# set timezone (TZ not considered in ubi8-minimal image)
RUN microdnf update &&\
    microdnf reinstall tzdata &&\
    ln -sf /usr/share/zoneinfo/Europe/Rome /etc/localtime &&\
    microdnf clean all

I’m not a fan of custom docker images, because they need to be maintained. I would mount timezone from host OS (if it’s properly configured there) as read only volume, e.g.:

-v /etc/localtime:/etc/localtime:ro

That’s one valid choice, but it would mean having to run the image on an host where such /etc/localtime is available. In our case we run it on different host systems so preferred a self-contained approach!

I am experiencing same problem with Quay too, even mounting /etc/localtime from host did not help. Any solutions?
Note: I have experienced a strange behaviour when I set TZ env to UTC+4, container time shows UTC-4.