Configure timezone in dockerized Nginx + PHP-FPM

后端 未结 1 1501
抹茶落季
抹茶落季 2021-02-06 06:58

I need to set the default timezone in a Dockerfile. I have two containers (nginx and php7-fpm).

When I enter the PHP container\'s bash and run php --info | grep tim

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 07:19

    There are two type of Time zone settings. One is a system level. That you can set using /etc/localtime

    See the Dockerfile steps below

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

    PS: Taken from https://serverfault.com/questions/683605/docker-container-time-timezone-will-not-reflect-changes

    Also you can refer to another article Using docker-compose to set containers timezones

    Next is the PHP/APP level setting. For that you can create a ini file. Which can be done by adding below line to Dockerfile

    RUN printf '[PHP]\ndate.timezone = "US/Central"\n' > /usr/local/etc/php/conf.d/tzone.ini
    

    0 讨论(0)
提交回复
热议问题