简体   繁体   English

Docker-Compose 不会处理我的 php.ini 文件

[英]Docker-Compose won't volume my php.ini file

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.我正在尝试使用 docker-compose 来处理我的 php.ini 文件,以便我可以在本地机器上即时进行更改以查看它如何影响主机。 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.不幸的是,到目前为止,我能够将 php.ini 文件放入容器的唯一方法是直接在 Dockerfile 中创建。

Attached is an image of the container running fine with the current settings below.附件是使用以下当前设置正常运行的容器的图像。

在此处输入图片说明

My Dockerfile is below:我的 Dockerfile 如下:

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:我的 docker-compose.yml 文件如下:

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.我尝试按照此处的建议,通过创建 custom.ini 文件并将其安装在该位置, 无法更新 Docker 容器中的 php.ini 文件 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.我认为我实际上做对了,因为如果您查看我为 phpinfo() 附加的图像,您可以看到在附加的 .ini 文件下解析了我的 custom.ini 最后。 I did a test though by setting asp_tags = On instead of Off and I can't.我通过设置 asp_tags = On 而不是 Off 做了一个测试,但我不能。 phpinfo() will always show it as off. phpinfo() 将始终显示为关闭。 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 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). 我找到了答案,将一个名为custom.php.ini的文件放在config目录中(如果您遵循我的目录结构)。

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. 默认情况下,多余php文件的扫描目录将在conf.d目录中查找。 These files will overwrite the settings of the main php.ini. 这些文件将覆盖主要php.ini的设置。 I tested this with the asp_tag option turning it Off and On. 我使用asp_tag选项将其关闭和打开进行了测试。 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 进行这项工作的技巧是使用docker-compose down而不是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. PHP仅在启动时加载配置文件一次,而其他文件仅加载一次,因此在更改php.ini或自定义文件后,需要将此docker-compose下来以强制进行更改。

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如果你正在使用类似wodby( docker4phpdocker4drupal )或兰多或试图找到“为什么php.ini中不起作用”(像我)的答案,这些工具都是用自己的方式来配置传递到PHP

https://github.com/wodby/php#php-and-php-fpm-configuration https://github.com/wodby/php#php-and-php-fpm-configuration

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如果你正在使用类似wodby( docker4phpdocker4drupal )或兰多或试图找到“为什么php.ini中不起作用”(像我)的答案,这些工具都是用自己的方式来配置传递到PHP

https://github.com/wodby/php#php-and-php-fpm-configuration 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.我在这里发布这个答案是因为我浪费了 2 个小时来找到答案,而我是从谷歌进入这个问题的。 I want to save some time to others.我想为其他人节省一些时间。

Mounting of custom.php.ini will not help.挂载 custom.php.ini 无济于事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM