Docker-Compose不会卷我的php.ini文件 [英] Docker-Compose won't volume my php.ini file

查看:103
本文介绍了Docker-Compose不会卷我的php.ini文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我的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"]

我的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"

我尝试按照此处的建议进行操作,无法更新php. Docker容器中的ini文件,方法是创建一个custom.ini文件并将其安装在该位置.我认为我确实正确地做到了这一点,因为如果您查看我为phpinfo()附加的图像,则可以看到在解析后的我的custom.ini文件位于其他.ini文件下.我通过设置asp_tags = On而不是Off进行了测试,但我做不到. phpinfo()将始终显示为关闭.尽管加载了我的配置文件,但请参阅我的附件中显示它的图像.

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?

使用的额外文件

运行

#!/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

我的文件结构

推荐答案

我找到了答案,将一个名为custom.php.ini的文件放在config目录中(如果您遵循我的目录结构).

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

默认情况下,多余php文件的扫描目录将在conf.d目录中查找.这些文件将覆盖主要php.ini的设置.我使用asp_tag选项将其关闭和打开进行了测试.只要您执行以下操作,它就可以正常工作.

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.

完成这项工作的技巧是使用 docker-compose down 而不是 docker-compose kill

The trick to making this work is to use docker-compose down instead of docker-compose kill

这将删除容器及其缓存文件. PHP仅在启动时加载配置文件一次,而其他文件仅加载一次,因此在更改php.ini或自定义文件后,需要将此docker-compose下来以强制更改.

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.

这篇关于Docker-Compose不会卷我的php.ini文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆