Docker Timezone in Ubuntu 16.04 Image

前端 未结 10 1775
借酒劲吻你
借酒劲吻你 2020-12-13 10:40

I have created a Docker container using the Ubuntu 16.04 image.

docker run -it -d --name containername -v /var/www/public --privileged ubuntu
10条回答
  •  清歌不尽
    2020-12-13 10:55

    As said here, the secret is that dpkg-reconfigure tzdata simply creates /etc/localtime as a copy, hardlink or symlink (a symlink is preferred) to a file in /usr/share/zoneinfo. So it is possible to do this entirely from your Dockerfile. Consider:

    ENV TZ=America/Los_Angeles
    RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    

    And as a bonus, TZ will be set correctly in the container as well.

    This is also distribution-agnostic, so it works with pretty much anything Linux.

提交回复
热议问题