can't update php.ini file in Docker container - php

I'm trying to set Magento2 on Docker with Nginx & PHP7.
I've added a custom php.ini file as recommended by the PHP7 Docker image. I can see from phpinfo.php that it's loading my php.ini file but none of my updates are there.
It should be:
memory_limit = 2G
max_execution_time = 800
I've checked the PHP container and I can see the php.ini file is there with the correct settings, or so I think?
$ docker exec -it mymagento2docker_php_1 /bin/bash
# cat /usr/local/etc/php/php.ini
; This file is created automatically by the docker build
memory_limit = 2G
max_execution_time = 800
What am I doing wrong? Below are some more details.
Docker Project
.
├── docker-compose.yml
├── index.php
├── magento2
│   ├── [DIRECTORIES & FILES OMMITED]
│  
├── nginx
│   ├── Dockerfile
│   ├── default.conf
│   └── nginx.conf
├── output.txt
├── php
   ├── Dockerfile
    └── config
   └── php.ini
docker-compose.yml
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
php:
build: ./php/
expose:
- 9000
links:
- mysql
volumes_from:
- app
app:
image: php:7.0-fpm
volumes:
- ./magento2:/var/www/html
command: "true"
mysql:
image: mysql:latest
volumes_from:
- data
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: mage2
MYSQL_DATABASE: mage2
MYSQL_USER: mage2
MYSQL_PASSWORD: mage2
data:
image: mysql:latest
volumes:
- /var/lib/mysql
command: "true"
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
links:
- mysql
environment:
PMA_HOST: mysql
php/Dockerfile
FROM php:7.0-fpm
# Install dependencies
RUN apt-get update \
&& apt-get install -y \
cron \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libxslt1-dev
# Configure the gd library
RUN docker-php-ext-configure \
gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
# Install required PHP extensions
RUN docker-php-ext-install \
gd \
intl \
mbstring \
mcrypt \
pdo_mysql \
xsl \
zip \
soap
# Install the 2.4 version of xdebug that's compatible with php7
RUN pecl install -o -f xdebug-2.4.0
COPY config/php.ini /usr/local/etc/php/
## php/config/php.ini ##
; This file is created automatically by the docker build
memory_limit = 2G
max_execution_time = 800
UPDATE
I've tried restarting nginx with the below, but it did not work.
$ docker exec -it mymagento2docker_php_1 /bin/bash
# /etc/init.d/nginx restart
bash: /etc/init.d/nginx: No such file or directory
# service nginx restart
nginx: unrecognized service
# nginx -s reload
bash: nginx: command not found
# exit
$ docker restart mymagento2docker_nginx_1
mymagento2docker_nginx_1
$ docker exec -it mymagento2docker_nginx_1 /bin/bash
# /etc/init.d/nginx restart
Restarting nginx: nginxross in ~/my-magento2-docker
$ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------------------------
mymagento2docker_app_1 true Exit 0
mymagento2docker_data_1 docker-entrypoint.sh true Exit 0
mymagento2docker_mysql_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp
mymagento2docker_nginx_1 nginx -g daemon off; Exit 0
mymagento2docker_php_1 php-fpm Up 9000/tcp
mymagento2docker_phpmyadmin_1 /run.sh phpmyadmin Up 0.0.0.0:8080->80/tcp
ross in ~/my-magento2-docker
$ docker-compose up -d
Starting mymagento2docker_app_1
Starting mymagento2docker_data_1
mymagento2docker_mysql_1 is up-to-date
mymagento2docker_phpmyadmin_1 is up-to-date
mymagento2docker_php_1 is up-to-date
Starting mymagento2docker_nginx_1
ross in ~/my-magento2-docker
$ docker exec -it mymagento2docker_nginx_1 /bin/bash
# service nginx restart
Restarting nginx: nginxross in ~/my-magento2-docker
$ docker-compose up -d
Starting mymagento2docker_app_1
Starting mymagento2docker_data_1
mymagento2docker_mysql_1 is up-to-date
mymagento2docker_phpmyadmin_1 is up-to-date
mymagento2docker_php_1 is up-to-date
Starting mymagento2docker_nginx_1
ross in ~/my-magento2-docker
$ docker exec -it mymagento2docker_nginx_1 /bin/bash
# nginx -s reload
2016/10/05 14:07:43 [notice] 12#12: signal process started
#

Add a volumes: section to your php service in the docker-compose.yml file, map a local directory with a custom.ini file to /usr/local/etc/php/conf.d, and restart your container. Whatever valid settings in that file will override those from the main php.ini file. (Incidentally you can do the same with MySQL but not with Nginx).
This works in my own project:
php:
volumes:
- ./localpath/custom.ini:/usr/local/etc/php/conf.d/custom.ini

i think you have to reload the nginx config.
i dont know which OS your php container uses, but try inside of the container some of these:
# /etc/init.d/nginx restart
# service nginx restart
# nginx -s reload
my logical reason is, that you install php ( and start it at the same time ) and after all you copy the new config.

This is what happened :
- If you map the php.ini from host to container, make sure that file (php.ini) must exist on host before you launch the container. Otherwise, the container will not start
- Please check if docker was able to read your php.ini file (check permission, sometime docker is running as different user and can't access host file which belongs to root)
- Every time you update php.ini, you must restart php-fpm (get inside the container and restart the php-fpm to test, do not rebuild container) , and clear cache (if you enable opcache)

Related

Opening Docker container port on localhost in browser returns empty response

I'm trying to run a web project from a Docker container,
when I Dockerize the application on a macBook with an intel chip, everything runs fine and I can make a call to the Docker container. But when I run the same project, with the same setup on my M2 MacBook Air, the browser returns an empty response.
("this page isn't working" --> in Chrome)
This happens even though the containers appear to be running...
(Both containers are green lit up --> in Docker Desktop)
The container makes use of an Nginx service and a php service. The .yml file looks as below:
Docker-compose.yml
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: php:8.0.6-fpm
container_name: Asset-Service
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: Asset-Service
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:stable
container_name: Asset-Web-Server
restart: unless-stopped
tty: true
ports:
- "8087:80"
- "4487:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
My Dockerfile is the following, even though I don't think that this file causes the problem:
Dockerfile
FROM php:8.0.6-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
USER root
RUN apt-get update && apt-get install -y \
mariadb-client-10.3 \
libcurl4-openssl-dev \
pkg-config \
libssl-dev \
libpng-dev \
libzip-dev \
libonig-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
nano
RUN pecl uninstall mongodb
RUN pecl install mongodb
RUN echo "extension=mongodb.so" >> /usr/local/etc/php/conf.d/mongodb.ini
# Clear cache
## RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
#RUN docker-php-ext-enable mongodb
# Install composer
## RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -fg 1000 www
RUN id -u 1000 >/dev/null 2>&1 || useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
The container logs look normal and the ports in the inspect tab show 0.0.0.0:8087 and 0.0.0.0:4487.
Is this a recurring issue with the apple silicon version of Docker,
and is there anything I can do about it?
I have already tried to replicate the issue on an Intel macBook, but got the desired result instead of the empty response.
On my M2 I tried reinstalling Docker and rebuilding the containers but this didn't seem to fix anything...
Nevermind this issue.
This problem occurred when trying to build the containers from the Desktop folder.

Laravel application performance issue on Docker for Windows

I am trying to run my laravel application inside docker containers on my laptop (during development) and finding that the speed of the application is drastically slow when compared to running it using XAMPP for example.
My laptop is running Windows 10 Pro (64-Bit) with i7-6700HQ CPU, 16 GB RAM and SSD.
When I run my app in docker for windows, average page load time is approx 3.5 Seconds.
Running it on local XAMPP, average page load time is approx 350 Milliseconds (0.35 Second).
For my docker setup, I use the following image/Dockerfile:
FROM alpine:3.8
MAINTAINER Latheesan Kanesamoorthy
RUN apk add \
--no-cache \
--update \
apache2 \
composer \
curl \
php7 \
php7-apache2 \
php7-curl \
php7-bcmath \
php7-dom \
php7-mbstring \
php7-pdo_mysql \
php7-session \
php7-sockets \
php7-tokenizer \
php7-xml \
php7-xmlwriter \
php7-fileinfo \
&& mkdir -p /run/apache2 \
&& ln -sf /dev/stdout /var/log/apache2/access.log \
&& ln -sf /dev/stderr /var/log/apache2/error.log
COPY ./image/*.conf /etc/apache2/conf.d/
COPY ./image/php.ini /etc/php7/conf.d/99_custom.ini
RUN mkdir -p /storage/framework/testing
RUN mkdir -p /storage/framework/views
RUN mkdir -p /storage/framework/sessions
RUN mkdir -p /storage/framework/cache/data
RUN chown -R apache:apache /storage
WORKDIR /app
COPY ./src/composer.* ./
RUN composer install -n --no-autoloader --no-scripts --no-progress --no-suggest
COPY src .
RUN composer dump-autoload -o -n
EXPOSE 80
and docker-compose.yml:
version: '2.1'
services:
mysql:
container_name: myapp-mysql
mem_limit: 512M
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: myapp
MYSQL_DATABASE: myapp
MYSQL_USER: myapp
MYSQL_PASSWORD: myapp
ports:
- "35000:3306"
redis:
container_name: myapp-redis
image: redis:latest
redis-commander:
container_name: myapp-redis-commander
image: rediscommander/redis-commander:latest
hostname: redis-commander
restart: always
environment:
- REDIS_HOSTS=local:redis:6379
ports:
- "7050:8081"
links:
- redis
app:
container_name: myapp-app
mem_limit: 512M
build:
context: ""
dockerfile: image/Dockerfile
env_file:
- image/env/development
volumes:
- ./src:/app:cached
ports:
- "25000:80"
entrypoint: httpd -DFOREGROUND
links:
- mysql
- redis
and I use the following commands to boot it up:
docker-compose down --remove-orphans
docker-compose up -d --build
docker exec myapp-app composer install --prefer-dist --no-suggest
docker exec myapp-app php artisan cache:clear
docker exec myapp-app php artisan migrate:fresh --seed
As you can see, the docker version uses redis as the driver for: cache, eloquent model cache, queue and session.
Locally for XAMPP, I am simply using file driver for all.
Any idea why the performance is so slow on docker?
P.S. The reason why I want to try developing using the docker environment is so that I can keep my development and production environment identical.

Running TYPO3 in Docker via wget ''

I'm running few Docker Containers view at the Code below. I would like to integrate the TYPO3 via w get but get an ERROR: Service 'app' failed to build: ADD failed: stat /mnt/sda1/var/lib/docker/tmp/docker-builder400003814/|: no such file or directory how can i solve it? and move the necessary folders into my www/ path thanks :)
docker-compose up -d
`docker-compose.yml`
version: '2'
services:
version: '2'
services:
#######################################
# PHP application Docker container
#######################################
app:
build:
context: .
dockerfile: Dockerfile
links:
- mysql
ports:
- "8000:80"
#######################################
# MySQL server
#######################################
mysql:
build:
context: docker/mysql/
dockerfile: MySQL-5.7.Dockerfile
restart: always
env_file:
- etc/environment.yml
networks:
- php-network
#######################################
# PHP MY ADMIN
#######################################
myphpadmin:
build:
context: docker/myphpadmin
dockerfile: Dockerfile
restart: always
links:
- mysql
ports:
- 8080:80
environment:
- PMA_HOST=mysql
- VIRTUAL_PORT=80
networks:
- php-network
networks:
php-network:
driver: bridge
`Dockerfile` for PHP & APACHE
FROM webdevops/php-apache-dev:ubuntu-16.04
ENV PROVISION_CONTEXT "development"
# Configure volume/workdir
WORKDIR /app/
Typo3 `Dockerfile`
FROM ubuntu:latest
ENV TYPO3_VERSION 7.6.16
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 php7.0 php7.0-mysql libapache2-mod-php7.0 curl lynx-cur php7.0-curl php7.0-gd php-imagick php7.0-soap php7.0-xml php7.0-zip
# Enable apache mods.
RUN a2enmod php7.0
RUN a2enmod rewrite
# Update the PHP.ini file, enable <? ?> tags and quieten logging.
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini
ADD https://get.typo3.org/7.6 | tar -xzf - && \
RUN cd /var/www/html && \
ln -s typo3_src-* typo3_src && \
ln -s typo3_src/index.php && \
ln -s typo3_src/typo3 && \
ln -s typo3_src/_.htaccess .htaccess && \
mkdir typo3temp && \
mkdir typo3conf && \
mkdir fileadmin && \
mkdir uploads && \
touch FIRST_INSTALL && \
chown -R www-data. .
# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
# Expose apache.
EXPOSE 80
# Copy this repo into place.
ADD www /var/www/site
# Update the default apache site with the config we created.
ADD etc/apache-config.conf /etc/apache2/sites-enabled/000-default.conf
# By default start up apache in the foreground, override with /bin/bash for interative.
CMD /usr/sbin/apache2ctl -D FOREGROUND
That is however not really TYPO3 related.
I would suggest that you take a look at https://github.com/webdevops/TYPO3-docker-boilerplate which is well tested and just works out of the box.

PHP date.timezone not found with Docker & PHP-FPM

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. :-)

php docker link apache docker

I build 2 dockers, one docker with apache, one docker with php5, and I use docker-compose to start.
apache2 Dockerfile in directoy apache2:
FROM debian:latest
RUN apt-get update && apt-get install -y apache2
ADD test.php /var/www/html
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
and test.php:
<?php
phpinfo();
?>
php5 Dorckerfile in directory php:
FROM debian:latest
RUN apt-get update && apt-get install -y php5
docker-compose.yml:
apache:
build: ./apache2
container_name: apache
ports:
- "80:80"
links:
- "php5"
php5:
build: ./php
container_name: php
then I run:
docker-compose up
apache2 server start successfully. Then I access this server by http://server_ip, then I get index of debian.But when I access http://server_ip/test.php, just occur this:
<?php
phpinfo();
?>
php just doesn't work.And I don't why.
You can separate Apache and PHP with PHP-FPM. It is however that the DocumentRoot must be mounted on both containers.
Apache must be able to access the files locally (inside its container) as well as the PHP-FPM server.
I am currently working on the same, have a look at my docker-compose.yml here
https://github.com/cytopia/devilbox/blob/master/docker-compose.yml
Both volumes (in PHP and apache) are mounted to /shared/httpd
I would say its not possible to run seperate containers for php as apache module. I guess this is what Wolfgang meant.
If you want to seperate apache and php in two different containers you need to run php as fpm.
Have a look here for inspiration: How to correctly link php-fpm and Nginx Docker containers together?
If you need to run apache and php as apache_mod use a combined container like this: https://github.com/docker-library/php/blob/fec7f537f049aafd2102202519c3ca9cb9576707/5.5/apache/Dockerfile
from: https://hub.docker.com/_/php/
If you don't specifically need to separate Apache from PHP, then you might be good to go with an official php:5.6-apache image which comes with Apache out of the box.
For example, your docker-compose.yml might look something like this:
version: '3'
services:
web:
image: php:5.6-apache
ports:
- "8080:80" # Map container port 80 to host machine port 8080
volumes:
- ".:/var/www/html" # Mount current folder as volume to container at /var/www/html
Or, for a more real-life example, if you also need at least one of the following:
A custom web root (for Laravel, Symfony, etc)
Other Apache modules installed
Other PHP extensions installed
You might do something more like this:
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80" # Map container port 80 to host machine port 8080
environment:
APACHE_DOCUMENT_ROOT: "/var/www/yourapp.com/public"
volumes:
- ".:/var/www/yourapp.com" # Mount current folder as volume to container at /var/www/yourapp.com
And then your Dockerfile (which we reference from the docker-compose.yml above):
FROM php:5.6-apache
# Declare an environment variable with a default value for changing Apache's document root
# We will override this in docker-compose.yml
ENV APACHE_DOCUMENT_ROOT /var/www/html
# Configure web root
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
# Install additional Apache modules
# This example: mod_rewrite & mod_headers
RUN a2enmod rewrite headers
# Install additional PHP extensions
# This example: memcached & mysqli
# For other extensions see official docs:
# https://hub.docker.com/_/php (section: How to install more PHP extensions)
RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev \
&& pecl install memcached-2.2.0 \
&& docker-php-ext-enable memcached \
&& docker-php-ext-install -j$(nproc) mysqli

Categories