在dockerized Nginx + PHP-FPM中配置时区 [英] Configure timezone in dockerized Nginx + PHP-FPM

查看:115
本文介绍了在dockerized Nginx + PHP-FPM中配置时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Dockerfile中设置默认时区.我有两个容器(nginx和php7-fpm).

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

当我进入PHP容器的bash并运行php --info | grep timezone时,我得到:

When I enter the PHP container's bash and run php --info | grep timezone I get:

默认时区=> UTC

Default timezone => UTC

date.timezone =>无值=>无值

date.timezone => no value => no value

我的dockerfile如下:

My dockerfiles are the following:

nginx/Dockerfile:

FROM debian:jessie

RUN apt-get update && apt-get install -y nginx

ADD nginx.conf /etc/nginx/
ADD site.conf /etc/nginx/sites-available/

RUN ln -s /etc/nginx/sites-available/site.conf /etc/nginx/sites-enabled/site
RUN rm /etc/nginx/sites-enabled/default

RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf

RUN usermod -u 1000 www-data

CMD ["nginx"]

EXPOSE 80
EXPOSE 443

php-fpm/Dockerfile:

FROM php:7.0-fpm

RUN apt-get update && apt-get install -y git unzip

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version

RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Madrid /etc/localtime
RUN "date"

RUN docker-php-ext-install pdo pdo_mysql

RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

WORKDIR /var/www/site

我尝试使用类似问题的答案,但没有结果.

I've tried to use the answers of similar questions with no results.

注意:我正在使用docker-compose builddocker-compose up -d运行完整的堆栈,该堆栈恰好是这一个.

Note: I'm using docker-compose build and docker-compose up -d to run the complete stack, which is exactly this one.

推荐答案

有两种类型的时区设置.一个是系统级别.您可以使用/etc/localtime

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

请参阅下面的Dockerfile步骤

See the Dockerfile steps below

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

PS:摘自 https://serverfault.com/questions /683605/docker-container-time-timezone-not-reflect-changes

还可以参考另一篇文章使用docker-compose设置容器时区

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

接下来是PHP/APP级别设置.为此,您可以创建一个ini文件.可以通过在Dockerfile中添加以下行来完成

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

这篇关于在dockerized Nginx + PHP-FPM中配置时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆