无法在Docker容器中更新php.ini文件

时间:2016-10-05 13:38:15

标签: php nginx docker dockerfile php-ini

我试图用Nginx& amp ;;设置Magento2在Docker上PHP7。

我已根据PHP7 Docker image的建议添加了自定义php.ini文件。我可以从phpinfo.php看到它正在加载我的php.ini文件,但我的更新都没有。 enter image description here enter image description here enter image description here

应该是:

memory_limit = 2G
max_execution_time = 800

我已经检查了PHP容器,我可以看到php.ini文件中有正确的设置,或者我认为?

$ 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

我做错了什么?以下是一些更多细节,提前感谢!

Docker Project

.
├── docker-compose.yml
├── index.php
├── magento2
│   ├── [DIRECTORIES & FILES OMMITED]
│                   
├── nginx
│   ├── Dockerfile
│   ├── default.conf
│   └── nginx.conf
├── output.txt
├── php
    ├── Dockerfile
    └── config
        └── php.ini

搬运工-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

更新

我已尝试使用以下方法重新启动nginx,但它无效。

$ 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
# 

3 个答案:

答案 0 :(得分:26)

docker-compose.yml 文件中的 php 服务中添加卷:部分,使用 custom.ini 文件到 /usr/local/etc/php/conf.d ,然后重新启动容器。该文件中的任何有效设置都将覆盖主php.ini文件中的设置。 (顺便说一句,你可以用MySQL做同样的事情,但不能用Nginx做。)

这适用于我自己的项目:

php: volumes: - ./localpath/custom.ini:/usr/local/etc/php/conf.d/custom.ini

答案 1 :(得分:0)

我认为你必须重新加载nginx配置。 我不知道你的php容器使用哪个操作系统,但尝试在容器内部的一些:

# /etc/init.d/nginx restart

# service nginx restart

# nginx -s reload

我的逻辑原因是,您安装了php(并在同一时间启动它),然后复制新配置。

答案 2 :(得分:0)

这是发生了什么: -如果将php.ini从主机映射到容器,请在启动容器之前确保文件(php.ini)必须存在于主机上。否则,容器将无法启动 -请检查docker是否能够读取您的php.ini文件(检查权限,有时docker以其他用户身份运行,并且无法访问属于root的主机文件) -每次更新php.ini时,都必须重新启动php-fpm(进入容器并重新启动php-fpm进行测试,不要重建容器),并清除缓存(如果启用了opcache)