doufutao4428 2014-12-30 10:42
浏览 197
已采纳

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

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

  • 写回答

1条回答 默认 最新

  • dongluni0568 2014-12-31 13:27
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。