简体   繁体   English

Docker: PHP, Apache and MySQL in the same container / the same Dockerfile

[英]Docker: PHP, Apache and MySQL in the same container / the same Dockerfile

I need an image with all the 3 elements combined in one container.我需要一张将所有 3 个元素组合在一个容器中的图像。 But however I Google'd or searched over Docker Hub there I found no images to hold PHP , Apache and MySQL in the same container / Dockerfile. But however I Google'd or searched over Docker Hub there I found no images to hold PHP , Apache and MySQL in the same container / Dockerfile.

Can anybody suggest the way to create the desired container?有人可以建议创建所需容器的方法吗?

I would also appreciate the explanation for the rationale of why this kind of images/containers is not available?我也很感激解释为什么这种图像/容器不可用的原因?

As a side note I myself cannot imagine a point making a separation of the MySQL server in the different container feasible due to the fact that the DB itself is not saved with the container and there is only MySQL server in it.作为旁注,我自己无法想象在不同的容器中分离MySQL服务器是可行的,因为DB本身没有与容器一起保存,并且其中只有MySQL服务器。 So even MySQL being in the same container still perfectly decoupled from the DB itself.因此,即使MySQL在同一个容器中,仍然与DB本身完美分离。

Good Morning bob-12345早安 bob-12345

The Point of docker containers is to get a more flexible architecture. docker 容器的重点是获得更灵活的架构。

I will make a Example from my work life:我将从我的工作生活中举一个例子:

You have an application thats run on php7.0 you now want to test if it still works with php 7.3 so you just stops the php 7.0 container and starts the 7.3 one and checks your application.您有一个在 php7.0 上运行的应用程序,您现在想测试它是否仍然适用于 php 7.3,因此您只需停止 php 7.0 容器并启动 7.3 并检查您的应用程序。 Or you want to check if it still works with ngnx and php-fpm and so on...或者你想检查它是否仍然适用于 ngnx 和 php-fpm 等等......

So it is not recommended to put your webserver your coding layer and your persisent layer in one container due versioning issues.因此,由于版本控制问题,不建议将您的网络服务器您的编码层和持久层放在一个容器中。

If you still want to have it all in one.如果您仍然想将所有内容合二为一。 I would suggest you start with a plain debian/ubuntu/whatEverDistroYouPrefer and start building like you would do it on a regular webserver.我建议您从普通的 debian/ubuntu/whatEverDistroYouPrefer 开始,然后像在常规网络服务器上那样开始构建。

For Example:例如:

FROM debian:latest
RUN apt-get update \ 
&& apt-get install -y --no-install-recommends \ 
&& http \
&& php \ 
...

I hope Icould Help you:)我希望我能帮助你:)

PHP and Apache together in the same container is a good idea - in a practical sense, PHP is only really useful when combined with a webserver (generally speaking). PHP 和 Apache 放在同一个容器中是一个好主意 - 实际上,PHP 只有在与网络服务器结合使用时才真正有用(一般来说)。 The same cannot be said for MySQL. MySQL 则不能这样说。 There are real world problems around scalability, redundancy and availability that cannot be solved if the database server and volume is bundled up with the application code.如果数据库服务器和卷与应用程序代码捆绑在一起,则存在无法解决的可扩展性、冗余和可用性方面的现实问题。

Lets say you've deployed your "LAMP Image" into production and your website becomes really popular - cool.假设您已将“LAMP Image”部署到生产环境中,并且您的网站变得非常受欢迎 - 很酷。 You're receiving a lot of traffic and you need multiple instances of your application running.您收到大量流量,并且需要运行应用程序的多个实例。 You also need a read-replica of your database.您还需要数据库的只读副本。

How are you going to do that if everything is bundled into a single image?如果所有内容都捆绑到一个图像中,您将如何做到这一点? You're forced to run the same number of MySQL instances as the number of applications.您被迫运行与应用程序数量相同数量的 MySQL 实例。

The later me to answer the question of the earlier me.越晚的我回答越早的我的问题。

The need to have PHP and MySQL in the same container comes from a wish to make the portable package of these.将 PHP 和 MySQL 放在同一个容器中的需要来自于制造这些便携式 package 的愿望。

As later me sees it, the solution is not in combining both in the same container but instead under the same Docker Compose docker-compose.yml that easily connects 3 cotainers (Apache, PHP, MySQL).正如我后来看到的那样,解决方案不是将两者结合在同一个容器中,而是在同一个 Docker 下编写docker-compose.yml ,轻松连接 3 个容器(Apache、Z2FEC392304A5C23AC138DA22847F9C7、MySQL)。

Docker Compose is Docker containers orchestrator. Docker Compose是 Docker 容器编排器。 It can start, stop, remove, recreate a package of containers.它可以启动、停止、删除、重新创建一个 package 容器。 So it makes the package portable.因此,它使 package 具有便携性。

The quick Google search for docker-compose php apache mysql reveals a number of useful examples of docker-compose.yml . The quick Google search for docker-compose php apache mysql reveals a number of useful examples of docker-compose.yml . This is just one of them. 只是其中之一。

This is so much easier and fun with Docker / Compose as soon as you get used to it.使用 Docker / Compose 后,这将变得更加轻松有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM