Docker - 如何在 docker-compose.yml 中设置 Apache + PHP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41423349/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:23:48  来源:igfitidea点击:

Docker - how to set up Apache + PHP in docker-compose.yml

phpapachedockerdocker-composeubuntu-16.04

提问by laukok

I use this to set up nginx for PHP:

我用它来为 PHP 设置 nginx:

nginx:
    image: nginx:latest
    ports:
        - 8080:80
    volumes:
        - ./code:/code
        - ./site.conf:/etc/nginx/conf.d/site.conf
    links:
        - php
php:
    image: php:7-fpm
    volumes:
        - ./code:/code

But how about Apache? How can I set up Apache + PHP in docker-compose.yml?

但是阿帕奇呢?如何在 docker-compose.yml 中设置 Apache + PHP?

Following this guide:

遵循本指南

version: '2'

services:
  php:
    build: php
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./php/www:/var/www/html

Error:

错误:

ERROR: In file './docker-compose.yml' service 'version' doesn't have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.

Any ideas? I'm on Xubuntu 16.04.

有任何想法吗?我在 Xubuntu 16.04。

EDIT:

编辑:

After managing to upgrade docker-compose to 1.9, I try with this file below:

在设法将 docker-compose 升级到 1.9 后,我尝试使用以下文件:

version: '2'
services:
    php:
        build: php
        expose:
            - 9000
        volumes:
            - ./php/www:/var/www/html

    apache2:
        image: webdevops/apache:latest
        args:
            - PHP_SOCKET=php:9000
        volumes:
            - ./php/www:/var/www/html
        ports:
            - 80:80
            - 443:443
        links:
            - php

Error:

错误:

$ sudo docker-compose up -d
Building php
ERROR: Cannot locate specified Dockerfile: Dockerfile

Docker is such as pain!

Docker就是这样的痛苦!

Any ideas how to fix this?

任何想法如何解决这一问题?

回答by rokas

I would choose webdevops dockerized apache, because it has simple configuration:

我会选择 webdevops dockerized apache,因为它具有简单的配置:

version: '2'
services:
    php:
        build: php
        expose:
            - 9000
        volumes:
            - ./php/www:/var/www/html

    apache2:
        image: webdevops/apache:latest
        args:
            - PHP_SOCKET=php:9000
        volumes:
            - ./php/www:/var/www/html
        ports:
            - 80:80
            - 443:443
        links:
            - php

回答by Hemanathagiribabu

  1. We need to create a new folders /php/www in current path

  2. Create a file under php folder save as "Dockerfile" which contains as below without quote

  1. 我们需要在当前路径中创建一个新文件夹 /php/www

  2. 在 php 文件夹下创建一个文件,另存为“Dockerfile”,内容如下,不带引号

"FROM php:5.6-apache RUN docker-php-ext-install mysqli"

“从 php:5.6-apache 运行 docker-php-ext-install mysqli”

  1. Copy your docker-compose.yml file in your current folder where your "php" folder has.

  2. Create a sample file "index.php" under www folder (/php/www/index.php)

  3. Run in command prompt docker-compose up -d

  4. Open your browser type "localhost" you can see your sample file results.

  1. 将 docker-compose.yml 文件复制到“php”文件夹所在的当前文件夹中。

  2. 在 www 文件夹(/php/www/index.php)下创建一个示例文件“index.php”

  3. 在命令提示符下运行 docker-compose up -d

  4. 打开你的浏览器输入“localhost”你可以看到你的示例文件结果。

Note: Above steps as per above mentioned docker-compose.yml file.

注意:以上步骤按照上面提到的 docker-compose.yml 文件。