如何在nginx和php容器之间进行通信

我有 PHP Web应用程序</ code>,我想将其转换为 docker < /code>.

我有这些容器</ p>

  mysql 
php
nginx
</ code> </ pre>

我的主机文件夹中的源代码为 / var / www / site1 </ code> </ p>

现在当我启动nginx时,我可以挂载 site1 </ code>到nginx为 / usr / nginx / share / html </ code> </ p>

但我不确定如何与PHP conainer链接。 我不能单独安装PHP的PHP容器,或者我需要有一些网络服务器和PHP </ p>
</ div>

展开原文

原文

I have PHP web application and i want to convert it into docker.

I have these containers

mysql
php
nginx

I have source code in my host folder as /var/www/site1

Now when i launch nginx , then i can mount site1 to nginx as /usr/nginx/share/html

But i am not sure how does i link with PHP conainer. Can't i have stand alone PHP container with only PHP installed or I need to have some webserver along with PHP

dongqian9567
dongqian9567 php容器刚安装了所有库的php
接近 6 年之前 回复
douhui1630
douhui1630 PHP容器中有什么?PHP文件或一些实际安装?
接近 6 年之前 回复

1个回答



我对docker容器的看法是每个容器通常代表一个进程</ em>。 例如。 您的示例中的 mysql </ em>或 nginx </ em>。 容器通常相互通信使用网络或通过卷中的共享文件。</ p>

每个容器都运行自己的操作系统(通常在 Dockerfile </ code>中的> FROM </ code> - 部分。在你的情况下,你建议 nginx </ em> -container在一个进程中运行一个操作系统并且< em> php-libraries </ em>在不同的进程中运行(在不同的操作系统中)。我不确定这是否可行,但似乎这是一种奇怪的处理方式。</ p>

我建议您创建两个容器:</ p>


  • nginx + php </ code> - 此容器包含PHP安装以及 Nginx-stuff </ li>
  • mysql </ code> - 此容器包含数据库</ li>
    </ ul>

    容器可以通过经典进行通信 网络或作为链接容器。</ p>

    但是,你的PHP文件 希望执行(即 您的网站)应作为数据量动态安装在上 nginx + php </ code>容器或数据量容器。</ p>
    </ DIV>

展开原文

原文

My view on docker containers is that each container typically represents one process. E.g. mysql or nginx as in your example. Containers typically communicates with each other using networking or via shared files in volumes.

Each container runs its own operating system (typically specified in the FROM-section in your Dockerfile. In your case, you are suggesting that the nginx-container runs in one process with one operating system and that the php-libraries run in a different process (in a different os). I'm not sure if this is doable but it seems as if it is a strange way of doing things.

My suggestion is that you create two containers:

  • nginx+php - this container holds the PHP installation as well as the Nginx-stuff
  • mysql - this container contains the database

The container can communicate via classic networking or as linked containers.

However, the PHP-files that you wish to execute (i.e. your website) should be dynamically mounted as a data volume on the nginx+php container or as data volume container.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐