Docker Community Forums

Share and learn in the Docker community.

Timezone issue inside a lamp container


(Yoritomo) #1

Hello all

I discovered Docker not longtime ago, that is exactly what i need to run applications on previous versions of PHP under Ubuntu.

I installed Dolibarr which is a commercial management PHP software, it is running but the pages are permanently polluted by dose of warning like this :slight_smile:

`

> Warning: getdate(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/dolibarr/htdocs/core/lib/functions.lib.php on line 1702

I searched a lot on this problem and i could find it is a problem of the timezone not set inside the container, i tried a lot of tries but nothing drove to success.

There is my docker-compose.yml file :

version: '2'


services:
    web:
        image: lavoweb/php-5.6
            
        ports:
            - "80:80"
        volumes:
            - ~/www:/var/www/html            
            - "/etc/timezone:/etc/timezone:ro"
            - "/etc/localtime:/etc/localtime:ro"
            
        links:
            - db:db
        
      
    db:
        image: mysql:5.5
        volumes:
            - ~/mysql:/var/lib/mysql
        ports:
            - "3306:3306"
        environment:
            - MYSQL_ROOT_PASSWORD=root
            
    myadmin:
        image: phpmyadmin/phpmyadmin
        ports:
            - "8080:80"
        links:
            - db:db

`

Please if anyone as a solution , let me know

Thanks a lot


(Yoritomo) #2

Good evening

Sorry, looks like i made a mistake , i should post it in open sources projects , please can an admin move it to the right section ? I will have then more chances to get an answer.

Thanks


(Emily Shepherd) #3

This is a PHP configuration thing - you need to specifically tell it what timezone you’re using because it doesn’t care about the system one. There are two ways to do this:

Method 1: Explicitly Set the Timezone in your PHP script

If you can edit your PHP code, you can simply add the following statement, before you start interacting with date functions:

 date_default_timezone_set('UTC');

Method 2: Set the Timezone in the PHP Config

If you don’t want to / can’t edit your PHP files, and you want a more “overall” solution, you can just update the config in the box itself. Create a file in your project called something like “timezone.ini” which contains:

date.timezone=UTC

Then update your docker-compose to include it in the PHP config directory:

volumes:
        - ~/www:/var/www/html            
        - "/etc/timezone:/etc/timezone:ro"
        - "/etc/localtime:/etc/localtime:ro"
        - "./timezone.ini:/usr/local/etc/php/conf.d/timezone.ini"

NB: In both of these examples, feel free to replace “UTC” with whatever timezone you actually want to use. A list of PHP timezones can be found here.

By the way, unless you included /etc/timezone and /etc/localtime for some other reason, they are not required for this fix to work :slight_smile:

Hope this helps :slight_smile: x


(Yoritomo) #4

Good evening

Thanks you so much for this complete and useful answer, i used your second method that was working directly, i read so many posts , i could not find such solution.

Nice name Emily it is the name of my daughter :wink: but her is french version Emilie

Thank you again