That's the reason why I need to use apt-get update and apt-get install -yq tzdata firstly on my Dockerfile when using the Ubuntu 20.04 for my Docker base image.
Of course, we can simplify my Dockerfile when using the Ubuntu to be the Docker base image:
FROM ubuntu:20.04
RUN apt-get update && \
apt-get install -yq tzdata
ENV TZ="Asia/Taipei"
Setting ENV TZ cannot be worked for setting system timezone.
For example, using the following
Dockefile
:When building above
Docker
image is done, running this image as container with interactive pseudo terminal:The timezone is correct, but current time is incorrect.
Then using the following
Dockerfile
and build them to be the Docker image:After building above Docker image is done, running this as a container with interactive pseudo terminal:
Ah, interesting, thank you. When I was using the "ENV TZ" method, my base image is
FROM node:16-slim
, and it worked perfectly when rundate
:Do you know why that works while
FROM ubuntu:20.04
does not? Is it b/c the node:16 image already set the tzdata like you did?The
node:16-slim
is based onDebian:10
image to build the Node.js version 16 environment.And it's worked for
Debian 10
when setting theENV
TZ to set the timezone.I think setting
ENV
TZ is not the common way to set system timezone on every Linux distributions.Hmm, you are right, just tried
FROM debian:10
, theENV TZ
way works. Seems just not working for ubuntu. Thank you for pointing out. TIL.If using the
ENV
to set TZ to set the timezone, it should have thetzdata
package installed on Linux distribution Docker base image.After investigating some common Linux distributions, the Debian and CentOS have the
tzdata
installed on their Base Docker images.And Ubuntu doesn't have the
tzdata
package on the Docker base image.That's the reason why I need to use
apt-get update
andapt-get install -yq tzdata
firstly on myDockerfile
when using theUbuntu 20.04
for my Docker base image.Of course, we can simplify my
Dockerfile
when using theUbuntu
to be the Docker base image:Got it, thanks for the awesome explanation. π