PHP Docker链接Apache Docker [英] php docker link apache docker
问题描述
我构建了2个docker,一个使用apache的docker,一个使用php5的docker,我使用docker-compose启动.
I build 2 dockers, one docker with apache, one docker with php5, and I use docker-compose to start.
直接在apache2中使用apache2 Dockerfile:
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"]
和test.php:
<?php
phpinfo();
?>
php5目录中的php5 Dorckerfile:
php5 Dorckerfile in directory php:
FROM debian:latest
RUN apt-get update && apt-get install -y php5
docker-compose.yml:
docker-compose.yml:
apache:
build: ./apache2
container_name: apache
ports:
- "80:80"
links:
- "php5"
php5:
build: ./php
container_name: php
然后我跑步:
docker-compose up
apache2服务器成功启动.然后,我通过 http://server_ip 访问此服务器,然后获得debian的索引.但是当我访问
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根本不起作用.我也不为什么.
php just doesn't work.And I don't why.
推荐答案
您可以将Apache和PHP与PHP-FPM分开.但是,DocumentRoot必须同时安装在两个容器上.
You can separate Apache and PHP with PHP-FPM. It is however that the DocumentRoot must be mounted on both containers.
Apache必须能够在本地(在其容器内)以及PHP-FPM服务器访问文件.
Apache must be able to access the files locally (inside its container) as well as the PHP-FPM server.
我目前正在从事相同工作,请在此处查看我的docker-compose.yml
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
两个卷(在PHP和apache中)都安装到/shared/httpd
Both volumes (in PHP and apache) are mounted to /shared/httpd
这篇关于PHP Docker链接Apache Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!