I'm trying to use docker-compose to volume my php.ini file so I can make changes on the fly on my local machine to see how it affects the host machine. Unfortunately the only way I've been able to get the php.ini file into the container is directly during creation in the Dockerfile so far.
Attached is an image of the container running fine with the current settings below.
My Dockerfile is below:
FROM ubuntu:14.04
MAINTAINER Joe Astrahan <jastrahan#poolservice.software>
VOLUME ["/var/www"]
RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-get update && \
apt-get install -y \
apache2 \
curl \
libcurl3 \
libcurl3-dev \
php5 \
php5-cli \
libapache2-mod-php5 \
php5-gd \
php5-json \
php5-ldap \
php5-mysqlnd \
php5-pgsql \
php5-curl \
mysql-client
COPY config/php.ini /etc/php5/apache2/php.ini
# install php-5.5.30
COPY config/install_php-5.5.30.sh /tmp/install_php-5.5.30.sh
RUN /bin/bash /tmp/install_php-5.5.30.sh
COPY config/apache_default.conf /etc/apache2/sites-available/000-default.conf
COPY config/run /usr/local/bin/run
RUN chmod +x /usr/local/bin/run
RUN a2enmod rewrite
#This will allow us to modify files in the container for testing if we need to
RUN apt-get update && \
apt-get install -y vim
EXPOSE 80
CMD ["/usr/local/bin/run"]
My docker-compose.yml file is below:
version: '2'
services:
dblive:
image: mysql:5.5.52
volumes:
- ./db_data_live:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ****
MYSQL_DATABASE: ****
MYSQL_USER: ****
MYSQL_PASSWORD: ****
dbdev:
image: mysql:5.5.52
volumes:
- ./db_data_dev:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD:****
MYSQL_DATABASE: ****
MYSQL_USER: ****
MYSQL_PASSWORD: ****
phpmyadmin:
depends_on:
- dblive
- dbdev
image: phpmyadmin/phpmyadmin
environment:
PMA_ARBITRARY : 1
restart: always
ports:
- "8081:80"
web:
build: ./
depends_on:
- dblive
- dbdev
volumes:
- ./web:/var/www
- ./config/php.ini:/etc/php5/apache2/conf.d/custom.ini
- ./logs/apache_error.log:/var/log/apache2/error.log
- ./logs/apache_access.log:/var/log/apache2/access.log
- ./config/apache_default.conf:/etc/apache2/sites-enabled/000-default.conf
restart: always
ports:
- "80:80"
- "443:443"
I tried following the advice here, can't upate php.ini file in Docker container, by creating a custom.ini file and mounting it in that location. I actually did it correctly I think because if you look at my image I attached for phpinfo(), you can see that under additional .ini files parsed my custom.ini is there at the end. I did a test though by setting asp_tags = On instead of Off and I can't. phpinfo() will always show it as off. Refer to my attached image of it showing it off despite loading my config file.
I'm not even sure if its really honoring any of the commands in there at all?
Extra Files Used
Run
#!/bin/bash
set -e
PHP_ERROR_REPORTING=${PHP_ERROR_REPORTING:-"E_ALL & ~E_DEPRECATED & ~E_NOTICE"}
sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php5/apache2/php.ini
sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php5/cli/php.ini
sed -ri "s/^error_reporting\s*=.*$//g" /etc/php5/apache2/php.ini
sed -ri "s/^error_reporting\s*=.*$//g" /etc/php5/cli/php.ini
echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/apache2/php.ini
echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/cli/php.ini
source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND
install_php-5.5.30.sh
#!/bin/bash
# install dependencies
apt-get -y update && \
apt-get install -y \
build-essential \
apache2-dev \
libxml2-dev
# download PHP 5.5.30 source code
cd /tmp
curl -fsSL http://php.net/get/php-5.5.30.tar.bz2/from/this/mirror | tar xjf -
cd php-5.5.30
# configure build options
./configure --prefix=/usr \
--with-config-file-path=/etc/php5/apache2 \
--with-config-file-scan-dir=/etc/php5/apache2/conf.d \
--disable-pdo \
--disable-json \
--enable-mbstring \
--with-apxs2
# compile and install
NUM_CORES=`cat /proc/cpuinfo | grep processor | wc -l`
make -j $NUM_CORES
make install
# configure extension directory
echo 'extension_dir="/usr/lib/php5/20121212"' >> /etc/php5/apache2/php.ini
# cleanup
rm -rf /tmp/php-5.5.30 /tmp/install_php-5.5.30.sh
My file structure
I found the answer, put a file called custom.php.ini in the config directory (if you are following my directory structure).
Set the volumes like this in my example...
volumes:
- ./web:/var/www
- ./config/custom.php.ini:/etc/php5/apache2/conf.d/custom.php.ini
By default the scan directory for extra php files will look in the conf.d directory. These files will overwrite the settings of the main php.ini. I tested this with the asp_tag option turning it Off and On. It works fine as long as you do the following below.
The trick to making this work is to use docker-compose down instead of docker-compose kill
This removes the containers and their cache files. PHP only loads the configuration file once at bootup and the other files so changing the php.ini or the custom file after requires this docker-compose down to force the change.
If you are using something like wodby (docker4php or docker4drupal) or lando or trying to find an answer "why php.ini doesn't work" (like me), these tools are using their own way to pass configuration into php
https://github.com/wodby/php#php-and-php-fpm-configuration
I am posting this answer here because I wasted 2 hours to find an answer and I came into this question from google. I want to save some time to others.
Mounting of custom.php.ini will not help.
Related
I am trying to automate the development of a project I am currently working on by creating a container on Docker that is composed of mysql, php and nginx to run a Symfony project. Here is my docker-compose.yml
services:
database:
container_name: database
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: rapidhcm
MYSQL_USER: admin
MYSQL_PASSWORD: password
ports:
- '4306:3306'
volumes:
- ./docker/mysql:/var/lib/mysql
php:
container_name: php
build:
context: .
ports:
- '9000:9000'
volumes:
- ./rapid-backend:/var/www/public
depends_on:
- database
nginx:
container_name: nginx
image: nginx:stable-alpine
ports:
- '8080:80'
volumes:
- ./rapid-backend:/var/www/public
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- database
And here is my Dockerfile:
FROM php:8.0-fpm
RUN apt update \
&& apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \
&& docker-php-ext-install intl opcache pdo pdo_mysql \
&& pecl install apcu \
&& docker-php-ext-enable apcu \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip
WORKDIR /var/www/html
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony5/bin/symfony /usr/local/bin/symfony
RUN git config --global user.email "email#email.com" \
&& git config --global user.name "Damian Kowalski"
The Dockerfile and docker-compose.yml files are in the root folder of the project, however the Symfony index.php file is situated in ./rapid-backend/public/index.php. How can I indicate that I want to serve that php file?
You would typically use only two containers: one for the database and one for the php-enabled web server.
You start from an php+apache image or an nginx image with php installed. Then you can bind-mount the web server's configuration files just as you did in your docker-compose.yaml for the nginx container.
You'd have something like this in your Dockerfile:
FROM php:8.2-apache AS production
ADD default.conf /etc/apache2/sites-available/default.conf
RUN # <...>
# Install tools and PHP dependencies
# apt-get update && \
# apt-get install -y <...> && \
# Configure docker php extensions, see image documenation on dockerhub
# docker-php-ext-configure <...> && \
# docker-php-ext-install <...> && \
# Maybe you want xdebug? In that case you'll also want to copy a .ini file
# pecl install xdebug && \
# Cleanup
# docker-php-source delete && \
# Install latest composer 2
# curl https://getcomposer.org/composer-2.phar > /usr/local/bin/composer && \
# chmod +x /usr/local/bin/composer && \
# Enable some apache mods if needed
# a2enmod rewrite headers expires xsend && \
# Some more cleanup if needed
# apt-get remove -y <...> && \
# apt-get clean
# If this image is to be used in a development environment, here you may want to create a user that you'll tell Apache to use with APACHE_RUN_USER, using the same UID as your own user on your host, so that you can bind-mount your sources in your docker-compose.yaml file without having permission issues.
# If however this is a deployment image, here you will probably want to "COPY" your source code in the image and to "RUN composer install".
with the appropriate apache configuration file default.conf that exposes your index.php (see the Symfony documentation at https://symfony.com/doc/current/setup/web_server_configuration.html for example configuration files).
Then your web server service in docker-compose.yaml could look like:
web-server:
build:
context: .
ports:
- '8080:80'
# If this is a dev environment, bind mount your source code, maybe also
# have a "user: ..." option here if you created one in the Dockerfile
volumes:
- ./rapid-backend:/var/www/public
It's a pretty open question but I hope this is a push in the right direction. Starting from here you can use docker-compose exec to run a bash shell inside your web server, and use composer to install Symfony and initialize your project.
I'm trying to load my custom .ini file
I've tried mounting the /usr/local/etc/php/conf.d directory to ./php so that I can add .ini files, but it doesn't work, I mean the local directory php gets created but it's empty.
One more thing I'm curious about, what if the same config already exists in any of those already loaded .ini file, will my custom .ini will overwrite those? (That's actually what I want).
This is my Dockerfile
FROM php:8.1.2-apache
RUN apt-get update
# 1. development packages
RUN apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libzip-dev \
libfreetype6-dev \
g++
# 2. apache configs + document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers
# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
pdo_mysql \
pdo_mysql \
zip
# 5. composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
And here's the docker-compose.yml
version: '3.5'
services:
# Laravel App
laravel:
build:
context: '.'
restart: always
volumes:
- .:/var/www/html
# - ./php:/usr/local/etc/php/conf.d (This doesn't work)
# MySQL
mysql:
image: mysql:8
restart: always
volumes:
- ./run/var:/var/lib/mysql
environment:
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
# Meilisearch
meilisearch:
image: getmeili/meilisearch:latest
restart: always
volumes:
- ./meilisearch/data.ms:/data.ms
environment:
- MEILI_MASTER_KEY=${MEILISEARCH_KEY}
networks:
default:
name: nginxproxymanager_default
external: true
Many thanks in advance :)
Set path direct to file
volumes:
- ./:/var/www
- ./Docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
Check my docker-compose for more information: https://github.com/JavierAgueroCL/docker-php7.4-with-db-extensions/blob/master/docker-compose.yml
My project is throwing the next error after restarting the docker container:
Warning: require(/var/www/ /var/www/
/vendor/composer/./symfony/polyfill-php80/bootstrap.php): Failed to
open stream: No such file or directory in
'vendor/composer/autoload_real.php line 71
My Dockerfile:
FROM php:8.0-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/project/
# Set working directory
WORKDIR /var/www/project
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libicu-dev \
libonig-dev \
libzip-dev
# install node
RUN curl -sL https://deb.nodesource.com/setup_current.x | bash -
RUN apt-get install -y nodejs
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql zip exif pcntl
RUN docker-php-ext-configure gd --enable-gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl
RUN pecl install xdebug && docker-php-ext-enable xdebug
RUN echo 'xdebug.client_port=9000' >> /usr/local/etc/php/php.ini
RUN echo 'xdebug.mode=debug' >> /usr/local/etc/php/php.ini
RUN echo 'xdebug.discover_client_host=true' >> /usr/local/etc/php/php.ini
RUN echo 'memory_limit = 4G' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www/project
RUN composer install
RUN npm install
RUN npm run dev
RUN php artisan storage:link
ENV PATH="vendor/bin:${PATH}"
# Change current user to www
USER www
RUN composer global require tightenco/tlint
ENV PATH="${PATH}:/home/www/.composer/vendor/bin"
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
My docker-compose:
...
project:
build:
context: ./project/.
dockerfile: Dockerfile
image: project:v0
restart: unless-stopped
tty: true
environment:
PHP_IDE_CONFIG: serverName=docker_project
XDEBUG_CONFIG: remote_host=172.17.0.1
SERVICE_NAME: project
SERVICE_TAGS: dev
volumes:
- /var/www/project/vendor/
- ./project:/var/www/project
- ./project/.docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- project-network
...
Inside container run ls vendor/symfony before restarting the container:
And after:
The error is solving if remove the vendor directory and run composer install.
I'm not a Jedi of the Docker.
Thanks for any help/suggestion!
In your volume section, you are mounting the host machine folder ./project to your container's /var/www/project:
volumes:
- /var/www/project/vendor/
- ./project:/var/www/project
- ./project/.docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
The vendor folder is built inside of you container by the RUN command. It's probably still there. But when you run docker-compose up, you instructed it to mask whatever inside with your host's ./project folder when running it. So the container don't see anything that you built before hand.
My advice is to only mount the folder that you need to change from time to time. For example:
volumes:
- /var/www/project/vendor/
# You're probably uploading files here
- ./project/public/assets:/var/www/project/public/assets
# Note: You might need to mount some other files / folders that changes
- ./project/.docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
Then the container will properly use the prebuilt /vendor while storing the thing that you need to keep in host.
For who are facing the same issue, just map the project folder except vendor folder:
services:
app:
volumes:
.:/var/www/html
/var/www/html/vendor
...
If you want to have all vendor files in the host machine, just copy them from the container to your host machine, so IDE (Like PHPSTORM) can identify composer packages:
$ cd /your/project/host/path
$ docker cp $(docker-compose ps -q app):/var/www/html/vendor .
I think I'm going to go crazy. I've searched all over and can't seem to find a working solution both here on Stack, GitHub and other far reaches of the interwebs.
On this particular project, running docker-compose build is taking FOREVER. It didn't use to be this way, and on other projects that use Docker, it's not an issue at all. And by forever... I'm talking around 10-15 minute build times when it used to only take around 2 minutes tops. I had two separate coworkers DL the same repo (one on Ubuntu 18, and the other on macOS 14.x). When they ran the build command, the entire process took ~2 minutes. Both of these people had never built this project before, so they were starting from complete scratch.
I've uninstalled/reinstalled Docker, ran a complete docker system prune -a, connected via wifi, connected via Ethernet, tried a different wifi network, tweaked my compose file, tweaked my docker file -- nothing.
My machine is a 2018 MacBook Pro with a quad-core 2.7GHz i7, running macOS 10.14.6 with 16gb of installed RAM with Docker Desktop 2.1.0.5.
I've allowed Docker Desktop to have up to 12gb or RAM. During the build process, my machine cpu usage spikes on average from 110% up to 270% running the com.docker.hyperkit process.
To be clear, it's hanging on the "Building php" (or "Building web") status message(s) before anything really even starts. After that, the actual build process runs smoothly and quick.
Here is my docker-compose.yaml file:
version: '3.1'
services:
db:
container_name: clientsname.db
hostname: db
image: mariadb:10.4.1-bionic
volumes:
- ./db-data:/var/lib/mysql:delegated
ports:
- 3307:3306
environment:
MYSQL_DATABASE: my_database
MYSQL_USER: my_user
MYSQL_PASSWORD: my_pass
MYSQL_ROOT_PASSWORD: my_pass
php:
container_name: clientsname.php
hostname: php
build:
dockerfile: php/php.dockerfile
context: ./
environment:
XDEBUG_CONFIG: remote_host=${REMOTE_HOST}
volumes:
- ../web:/var/www/web
- ../moodle:/var/www/moodle
- ../moodledata:/var/www/moodledata
- ./php/custom.ini:/usr/local/etc/php/conf.d/zzz-custom.ini
- ./php/z-errors.ini:/usr/local/etc/php/conf.d/z-errors.ini:delegated
- ./php/z-upload.ini:/usr/local/etc/php/conf.d/z-upload.ini:delegated
- ./php/z-xdebug.ini:/usr/local/etc/php/conf.d/z-xdebug.ini:delegated
depends_on:
- db
web:
container_name: clientsname.web
hostname: web
build:
dockerfile: nginx/nginx.dockerfile
context: ./
volumes:
- ../web:/var/www/web
- ../moodle:/var/www/moodle
- ../moodledata:/var/www/moodledata
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/ssl:/etc/nginx/ssl
- ./logs:/var/log/nginx
ports:
- 80:80
- 443:443
depends_on:
- php
- db
Here is the referenced php.dockerfile file:
FROM php:7.2.26-fpm
LABEL maintainer="My Clients Name"
# Environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_NO_INTERACTION=1
ENV COMPOSER_HOME=/usr/local/share/composer
# Working Directory
WORKDIR /var/www/web
WORKDIR /var/www/moodle
WORKDIR /var/www/moodledata
RUN rm /etc/apt/preferences.d/no-debian-php && apt-get update && apt-get install -y --no-install-recommends apt-utils \
build-essential \
php-soap \
libzip-dev \
libmagickcore-dev \
libmagickwand-dev \
libmagic-dev \
libpng-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libmemcached-dev \
zlib1g-dev \
nano \
sudo \
gnupg \
curl \
unzip && \
docker-php-ext-install soap pdo_mysql mysqli && \
docker-php-ext-install -j$(nproc) gd iconv && \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
pecl install zip-1.15.2 imagick memcached-3.0.4 xdebug && \
docker-php-ext-enable memcached imagick zip xdebug
# Install Composer, Node, Gulp, and SASS
RUN curl -s https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - && apt-get install -y nodejs && npm install npm#latest -g && npm install --global gulp-cli && npm config set unsafe-perm=true
# Export composer vendor path
RUN echo "" >> ~/.bashrc && echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
And the referenced nginx.dockerfile
FROM nginx:stable-alpine
RUN apk add --update bash && rm -rf /var/cache/apk/*
WORKDIR /var/www/web
It's driving me batty... what in the bloody hell could I be doing wrong? If there is anything I've left out that you'd all like to know, please let me know and I'll update the post.
UPDATE
Thanks to #BMitch and you all who have commented thus far. I took my entire /docker build directory and moved it into a test folder, and then created empty /web, /moodle, and /moodledata directories before running the build command. It started to compile immediately.
What's curious to me is that the other coworkers DL'd the same Git repo that I have and did not have any of the same issues. Oooh... come to think of it... I bet I know what the issue is.
This is from your build context (that's often the directory where you run your build, but can be overridden as you've done in the compose file). You have a large number of files, or large files, in the context directory that is sent before performing the build.
You can use .dockerignore which has a nearly identical format to .gitignore to exclude files from being sent on build. And with BuildKit (enabled if you export DOCKER_BUILDKIT=1 in recent versions of docker) it will only send context when you explicitly copy files and then only when those files have changed from what is available in the cache.
For more on the build context, see: https://docs.docker.com/engine/reference/commandline/build/
There's also the best practices: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
I'm creating a Symfony environment (PHP-FPM, Nginx, & more) with Docker & Docker-compose.
But, PHP does not use my php.ini and ignores the config (date.timezone parameter is not found in my Symfony application).
Of course, when I go on my container, the date.timezone is correctly set in the 2 php.ini (cli & FPM).
I don't understand why, but it works if I put my php.ini in /usr/local/etc/php/ folder (wtf)
Did I miss something?
docker-compose.yml :
nginx:
image: nginx
volumes:
- "./docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro"
links:
- "php:php"
ports:
- "80:80"
- "443:443"
working_dir: "/etc/nginx"
php:
build: docker/php
volumes:
- ".:/var/www:rw"
working_dir: "/var/www"
Dockerfile :
FROM php:5-fpm
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -y php5-common php5-fpm php5-cli php5-mysql php5-apcu php5-intl php5-imagick && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN sed -i 's/;date.timezone =/date.timezone = "Europe\/Paris"/g' /etc/php5/fpm/php.ini
RUN sed -i 's/;date.timezone =/date.timezone = "Europe\/Paris"/g' /etc/php5/cli/php.ini
RUN usermod -u 1000 www-data
Official PHP Docker Image use /usr/local/etc/php as base folder: see Dockerfile.
I've been facing the same problem for a while, the host machine had a correct date/time but every php container was in GMT instead of Europe/Paris or host date time.
For those of you who will search for a valid answer and need more precisions than #moliver answer, using sed in the dockerfile maybe not the best answer. Moreover, php.ini might not be created at building time. Here is the ls of /usr/local/etc/php in one of my php container.
root#6fd7bc929a7e:/usr/local/etc/php/conf.d# ls
docker-php-ext-bcmath.ini docker-php-ext-exif.ini docker-php-ext-mysqli.ini docker-php-ext-soap.ini docker-php-ext-xsl.ini
docker-php-ext-bz2.ini docker-php-ext-gd.ini docker-php-ext-pcntl.ini docker-php-ext-tidy.ini docker-php-ext-zip.ini
docker-php-ext-calendar.ini docker-php-ext-mcrypt.ini docker-php-ext-pdo_mysql.ini docker-php-ext-xmlrpc.ini ext-imagick.ini
(yes i added a lot of extensions, but no php.ini by default).
docker-compose is very flexible, you can add a volume containing php.ini info :
version: '2'
services:
php:
build: ./DOCKERFILES/phpdemo
container_name: applicationDEMO
volumes:
- "./conf/whatever.ini:/usr/local/etc/php/conf.d/whatever.ini"
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
And in your ./conf/whatever.ini
date.timezone = "Europe/Paris"
Hope this helps
I had this issue in my php:5.6-apache docker image.
I simply added these two lines in my dockerfile:
# use development php ini
RUN mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
# set default timezone
RUN sed -ri -e 's!;date.timezone =!date.timezone = "Europe/Paris"!g' /usr/local/etc/php/php.ini
It worked well. :-)