无法更新 Docker 容器中的 php.ini 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39875543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
can't update php.ini file in Docker container
提问by Holly
I'm trying to set Magento2 on Docker with Nginx & PHP7.
我正在尝试使用 Nginx 和 PHP7 在 Docker 上设置 Magento2。
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.
我已经按照PHP7 Docker image 的建议添加了一个自定义的 php.ini 文件。我可以从 phpinfo.php 看到它正在加载我的 php.ini 文件,但我没有更新。
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?
我已经检查了 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
What am I doing wrong? Below are some more details, thanks in advance!
我究竟做错了什么?下面是一些更多的细节,提前感谢!
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
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
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.
我试过用下面的方法重新启动 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
#
回答by otravers
Add a volumes:section to your phpservice in the docker-compose.ymlfile, map a local directory with a custom.inifile 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).
在docker-compose.yml文件中向php服务添加卷:部分,将带有custom.ini文件的本地目录映射到/usr/local/etc/php/conf.d,然后重新启动容器。该文件中的任何有效设置都将覆盖主 php.ini 文件中的设置。(顺便说一句,您可以对 MySQL 执行相同操作,但不能对 Nginx 执行相同操作)。
This works in my own project:
这适用于我自己的项目:
php:
volumes:
- ./localpath/custom.ini:/usr/local/etc/php/conf.d/custom.ini
php:
volumes:
- ./localpath/custom.ini:/usr/local/etc/php/conf.d/custom.ini
回答by Gabbax0r
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:
我认为您必须重新加载 nginx 配置。我不知道你的 php 容器使用哪个操作系统,但在容器内部尝试其中一些:
# /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.
我的逻辑原因是,您安装了 php(并同时启动它),毕竟您复制了新配置。
回答by Dylan B
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)
这是发生的事情: - 如果您将 php.ini 从主机映射到容器,请确保在启动容器之前该文件 (php.ini) 必须存在于主机上。否则,容器将无法启动 - 请检查 docker 是否能够读取您的 php.ini 文件(检查权限,有时 docker 以不同的用户身份运行并且无法访问属于 root 的主机文件) - 每次更新 php .ini,你必须重启php-fpm(进入容器并重启php-fpm进行测试,不要重建容器),并清除缓存(如果你启用了opcache)