Docker中PHP和Apache / httpd的高山变体 [英] Alpine variants of PHP and Apache/httpd in Docker

查看:179
本文介绍了Docker中PHP和Apache / httpd的高山变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试验Docker,并希望从本地MAMP堆栈移至Docker。当然,我偶然发现了 php:7.0 的官方图片,但我也想使用Apache,因此好像 php:7.0-apache 是要走的路。但是我看到有一个名为 php:7.0-alpine 的映像,它更苗条,而Apache也有两个版本,即 httpd:2.4 httpd:2.4-alpine

I am experimenting with Docker and want to move from a local MAMP stack to Docker. Of course I stumbled upon the official php:7.0 image but I want to use Apache as well so it seems as if php:7.0-apache is the way to go. However I saw that there is an image called php:7.0-alpine which is much slimmer while there are two versions for Apache as well namely httpd:2.4 and httpd:2.4-alpine.

是否有建议的组合方式将两者同时使用Apache和PHP(分离或组合)同时还具有较小的图像尺寸?此外,我想知道在哪里可以查看图像中的可用模块,因为我也想使用MariaDB和mod_rewrite,它们可能具有更多的依赖关系,因此为了减小体积而省略了这些依赖。

Is there any suggested combination to use both Apache and PHP (either separated or combined) while still having small image sizes? Furthermore I would like to know where I can review the available modules in the images since I want to use MariaDB and mod_rewrite as well which could possibly have more dependencies which have been omitted to keep the size small.

我遇到了这本非常详尽且很棒的教程,介绍了如何将nginx和PHP以及MySQL拆分为不同的容器但使用FCGI将PHP附加到nginx。这意味着我可以使用工具的所有不同的基于高山的图像,并使用FCGI链接它们。不幸的是,我从未听说过FCGI或与FCGI合作过,但我猜想还会有更多研究产生有关如何使用Apache实施此基础架构的信息。

I came across this very detailed and awesome tutorial on how to split up nginx and PHP as well as MySQL into different containers but attach PHP to nginx using FCGI. This implies that I can use all the different alpine-based images of the tools and link them using FCGI. Unfortunately I have never heard of or worked with FCGI but I guess some more research will yield information on how to implement this infrastructure using Apache.

推荐答案

使用FCGI运行Apache / NGINX和PHP



如果要在单独的容器中运行Apache和PHP,则需要使用PHP-FPM容器(例如,使用 php:7-fpm php:7-fpm-alpine 图片),然后使用FCGI将两者连接。默认情况下,官方PHP-FPM映像为此公开了TCP端口9000,在大多数情况下就足够了。

Running Apache/NGINX and PHP with FCGI

If you want to run Apache and PHP in separate containers, you'll need to use a PHP-FPM container (like for example, using the php:7-fpm or php:7-fpm-alpine image) and then use FCGI to connect the two. By default, the official PHP-FPM images expose the TCP port 9000 for this, which should be sufficient for most cases.

对于PHP-FPM,官方PHP映像应该可以正常使用(就大小而言, 7.0.14-fpm-alpine 标签的大小仅为3100万)。关于Apache,我喜欢使用 webdevops / apache 图片(我没有任何关联)。它还带有一个基于Alpine的版本,大小只有3,800万,并且可以与PHP-FPM很好地配合使用。

For PHP-FPM, the official PHP image should do fine (regarding size, the 7.0.14-fpm-alpine tag is only 31M in size). Regarding Apache, I've come to like the webdevops/apache image (I'm not affiliated in any way). It also comes with an Alpine-based version that is only 38M in size and works well together with PHP-FPM.

这里是如何启动单独的PHP-FPM和Apache容器的方法,使用FCGI链接在一起:

Here's how you start separate PHP-FPM and Apache containers, linked together using FCGI:

$ docker run -d \
    -v /path/to/data:/var/www/html \
    --name fpm \
    php:fpm-7.0.14-alpine
$ docker run -d \
    -v /path/to/data:/var/www/html \
    --name apache \
    --link fpm \
    -e WEB_PHP_SOCKET=fpm:9000 \
    -e WEB_DOCUMENT_ROOT=/var/www/html \
    webdevops/apache:alpine-3

要使用Nginx,只需将 webdevops / apache 图像替换为 webdevops / nginx

For using Nginx instead, simply substitute the webdevops/apache image with webdevops/nginx.

由于您还询问过要在图像中添加其他PHP扩展:官方PHP中对此进行了介绍图片的文档。您可以通过在自定义Dockerfile中运行 docker-php-ext-install 来向PHP基本映像添加自定义PHP扩展:

Since you've also asked about adding additional PHP extensions to your image: this is covered in the official PHP image's documentation. You can add custom PHP extensions to the PHP base image by running docker-php-ext-install in a custom Dockerfile:

FROM php:7.0.14-fpm-alpine
RUN docker-php-ext-install pdo_mysql

这可让您基于其中一个PHP-FPM基础映像来构建自定义映像,并在 Dockerfile中添加所需的所有扩展名

This allows you to build your custom image based on one of the PHP-FPM base images, adding all extensions that you require in the Dockerfile.

这篇关于Docker中PHP和Apache / httpd的高山变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆