Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-18153

java does not pick up --tz option in stripped-zoneinfo images

Linking RHIVOS CVEs to...Migration: Automation ...Sync from "Extern...XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Can't Do
    • Icon: Major Major
    • None
    • rhel-8.8.0
    • podman
    • None
    • None
    • None
    • rhel-container-tools
    • 3
    • False
    • False
    • Hide

      None

      Show
      None
    • None
    • None
    • None
    • Automated
    • None

      Some tzdata files like zoneinfo are manually stripped from some images, apparently as a brute-force way to decrease image size.

      I believe this explains some of the history:
      https://bugzilla.redhat.com/show_bug.cgi?id=1668185

      This results in java not picking up the --tz option. 

      Can we add the tzdata of the host if it's missing in the container:

      *Bind mount host /usr/share/zoneinfo/YOUR/TIMEZONE as /usr/share/zoneinfo/YOUR/TIMEZONE
      *Create /etc/localtime as symlink just as now.

      This would allow the --tz option to work, even if tzdata is not installed in the container (or is missing zoneinfo).

      \\\\\ Steps to Reproduce /////
      1) $ podman login
      registry.redhat.io
      $ vi Dockerfile-ubi9

      ~~~
      FROM registry.access.redhat.com/ubi9/ubi
      RUN dnf -y install java-11-openjdk-devel && \
      echo 'public class ZonedHello { public static void main(String[] args)

      { System.out.println(java.time.ZonedDateTime.now()); } }' > ZonedHello.java && \
      javac ZonedHello.java

      CMD ["/bin/bash", "-c", "ls -la /etc/localtime && mount | grep zoneinfo || true && echo \"Now with default timezone:\" && date && echo \"Java default sees the following timezone:\" && java ZonedHello && echo \"Forcing UTC:\" && TZ=Etc/UTC date"]
      ~~~

      $ docker build . --file Dockerfile-ubi9
      ...
      --> 3417ba7cb445

      $ podman run -ti --rm --tz=Europe/Berlin 3417ba7cb445
      lrwxrwxrwx. 1 root root 35 Dec 1 22:11 /etc/localtime -> ../usr/share/zoneinfo/Europe/Berlin
      Now with default timezone:
      Fri Dec 1 22:11:36 CET 2023
      Java default sees the following timezone:
      2023-12-01T22:11:36.728863+01:00[Europe/Berlin]
      Forcing UTC:
      Fri Dec 1 21:11:36 UTC 2023

      This shows java is picking up --tz=Europe/Berlin when the full tzdata package is installed.

      2) $ vi Dockerfile-ub9i-openjdk17

      ~~~
      FROM registry.access.redhat.com/ubi9/openjdk-17
      RUN echo 'public class ZonedHello { public static void main(String[] args) { System.out.println(java.time.ZonedDateTime.now()); }

      }' > ZonedHello.java && \
      javac ZonedHello.java

      CMD ["/bin/bash", "-c", "ls -la /etc/localtime && mount | grep zoneinfo || true && echo \"Now with default timezone:\" && date && echo \"Java default sees the following timezone:\" && java ZonedHello && echo \"Forcing UTC:\" && TZ=Etc/UTC date"]
      ~~~

      $ docker build . --file Dockerfile-ubi9-openjdk17
      ...
      --> 58d5382c7d5d

      $ podman run -ti --rm --tz=Europe/Berlin 58d5382c7d5d

      $ podman run -ti --rm --tz=Europe/Berlin 58d5382c7d5d
      rw-rr-. 1 root root 2335 Dec 1 22:18 /etc/localtime
      /bin/bash: line 1: mount: command not found
      Now with default timezone:
      Fri Dec 1 22:18:03 CET 2023
      Java default sees the following timezone:
      2023-12-01T21:18:03.964031456Z[GMT]
      Forcing UTC:
      Fri Dec 1 21:18:03 Etc 2023

      This shows java is not picking up --tz=Europe/Berlin when the tzdata package is stipped of zoneinfo.

              mheon@redhat.com Matt Heon
              rhn-support-mmillson Michael Millson
              Container Runtime Eng Bot Container Runtime Eng Bot
              Container Runtime Bugs Bot Container Runtime Bugs Bot
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: