作者:四月草上飞2602920415 | 来源:互联网 | 2023-01-23 21:20
我需要在Dockerfile中设置默认时区.我有两个容器(nginx和php7-fpm).
当我进入PHP容器的bash并运行时,php --info | grep timezone
我得到:
默认时区=> UTC
date.timezOne=>没有值=>没有值
我的dockerfiles如下:
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
我试图使用类似问题的答案而没有结果.
注意:我正在使用docker-compose build
并docker-compose up -d
运行完整的堆栈,就是这个.
1> Tarun Lalwan..:
有两种类型的时区设置.一个是系统级别.你可以设置使用/etc/localtime
请参阅下面的Dockerfile步骤
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-will-not-reflect-changes
您还可以参考另一篇文章使用docker-compose来设置容器时区
接下来是PHP/APP级别设置.为此,您可以创建一个ini文件.这可以通过在Dockerfile中添加以下行来完成
RUN printf '[PHP]\ndate.timezOne= "US/Central"\n' > /usr/local/etc/php/conf.d/tzone.ini