Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php docker link apache docker

I build 2 dockers, one docker with apache, one docker with php5, and I use docker-compose to start.

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

and test.php:

<?php
phpinfo();
?>

php5 Dorckerfile in directory php:

FROM debian:latest
RUN apt-get update && apt-get install -y php5

docker-compose.yml:

apache:
    build: ./apache2
    container_name: apache
    ports:
      - "80:80"
    links:
      - "php5"

php5:
    build: ./php
    container_name: php

then I run:

docker-compose up

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 just doesn't work.And I don't why.

like image 765
xina1i Avatar asked Oct 20 '15 07:10

xina1i


1 Answers

You can separate Apache and PHP with PHP-FPM. It is however that the DocumentRoot must be mounted on both containers.

Apache must be able to access the files locally (inside its container) as well as the PHP-FPM server.

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

Both volumes (in PHP and apache) are mounted to /shared/httpd

like image 152
cytopia Avatar answered Nov 15 '22 17:11

cytopia