7

I'm using Docker and Docker-compose to build a stack of nginx+php.

I'm trying to set the timezone in my .env file and use it in a Dockerfile, but I might be missunderstanding something from the documentation.

.env

# Timezone
TIMEZONE=Europe/Madrid

docker-compose.yml

version '2'

services:
    php:
        build: php7-fpm
        volumes:
            - ${APP_PATH}:/var/www/app
            - ./logs:/var/www/logs
        environment:
            TIMEZONE: ${TIMEZONE}

#[...more.stuff...]

php7-fpm/Dockerfile

FROM php:7.0-fpm
ARG TIMEZONE

#[...more.stuff...]

ENV TIMEZONE=${TIMEZONE}
RUN ln -snf /usr/share/zoneinfo/$TIMEZONE /etc/localtime && echo $TIMEZONE > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', $TIMEZONE > /usr/local/etc/php/conf.d/tzone.ini

The timezone is not set properly inside the container (running php --info | grep timezone inside the php container bash). If I write the zone manually in the Dockerfile, it works.

2
  • what is the actual problem here? Commented Aug 22, 2017 at 9:58
  • The timezone is not set properly inside the container. If I write the zone manually in the Dockerfile, it works. Commented Aug 22, 2017 at 10:03

1 Answer 1

7

You need to pass the build argument in docker compose

version '2'

services:
    php:
        build: 
          dockerfile: php7-fpm
          args:
            TIMEZONE: ${TIMEZONE}
        volumes:
            - ${APP_PATH}:/var/www/app
            - ./logs:/var/www/logs

The environment are passed to the running container and not to the buildfile. For the you need to pass args in the build section

Sign up to request clarification or add additional context in comments.

6 Comments

Yes, you can even pass those using docker-compose, see the compose file in my answer
i meant passing --build-arg at the docker build step, since he makes use of those before actually running the app (or at least that's how it looks to me)
With build: php7-fpm in the compose file. It means that docker-compose is building the image also
oh, missed that part. Thanks, i don't usually include a build step in my compose files
Clear now, thanks! By the way I think the parameter environment is not longer necessary.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.