dragon8899 2016-06-11 17:04
浏览 231
已采纳

在Docker Apache中使用Php

I'm trying to use docker but I have a lot of problem. Now i Want to use an apache container and use a volume of my php

my images are

  • nimmis/apache
  • 5.6-fpm

my docker ps is:

85e592d46fcc        nimmis/apache       "/my_init"               3 minutes ago       Up 3 minutes        0.0.0.0:8080->80/tcp   apacheBarno
c9bc486563bc        php:fpm             "php-fpm"                15 minutes ago      Up 15 minutes       9000/tcp               app_php

and I Started my apache with this command

docker run --name apacheFoo --volumes-from app_php -p 8080:80 -v `pwd`:/var/www/html --rm nimmis/apache

When I visit http://192.168.99.100:8080/ ( im on mac ) I can see the apache page.

when I visit http://192.168.99.100:8080/index.php I get <?php echo "hello" ?>

instead of "hello"

  • 写回答

2条回答 默认 最新

  • doumu1873 2016-06-11 22:53
    关注

    The reason of the behavior is that the apache image you are using (https://hub.docker.com/r/nimmis/apache/, right?) is a plain apache without php support. So it just serves your php code as plain text.

    You don't need two images in this case. Instead you need one image running Apache with php module. You can use the official php image (https://hub.docker.com/_/php/).

    Your Docker file can look like this:

    ```
    # see https://hub.docker.com/_/php/
    FROM php:5.6-apache
    
    # copy your source into the /var/www/html inside the container
    COPY . /var/www/html/
    ```
    

    Now you can build and run it like this

    ```
    docker build -t apache-foo-docker .
    docker run -d -p 8080:80 -v $(pwd):/var/www/html --name apacheFoo apache-foo-docker
    ```
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 wpf datagrid如何实现多层表头
  • ¥15 为啥画版图在Run DRC会出现Connect Error?可我Calibre的hostname和计算机的hostname已经设置成一样的了。
  • ¥20 网站后台使用极速模式非常的卡
  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)