本文介绍了在Docker容器中的phpfpm和nginx之间共享应用程序文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将简单的phpinfo.php部署到ECS(Amazon EC2容器服务).

I am trying to deploy simple phpinfo.php to ECS (Amazon EC2 Container Service).

有人告诉我,如果我 Dockerize 我的应用程序并将结果图像推送到Amazon ECR(弹性容器注册表),EC2可以轻松地从那里获取应用程序.

I was told that if I Dockerize my app and push resulting image to Amazon ECR (Elastic Container Registry), EC2 can easily get app from there.

我做到了,现在我又遇到了另一个障碍.

I did that and NOW I have hit another road block.

在EC2容器中部署后,问题是我的应用程序仅位于/var/www/html/文件夹中的phpfpm容器中,但在我的 nginx 中不可见>容器.

After deploying in EC2 container, the problem is that my app is in ONLY phpfpm container in folder /var/www/html/ but IT IS NOT VISIBLE IN my nginx container.

由于这个问题,nginx无法交付我的应用程序.

Due to this problem, nginx does not delivery my app.

请注意,app不在主机设备EC2中,也不在nginx中,它仅在php-fpm中.如何解决这个问题呢?请指教.谢谢

Please note that app is not in the host device EC2, nor it is in nginx, it is only in php-fpm. How to solve this problem? Please advise. Thanks

docker-compose.yml

docker-compose.yml

version: '2'

services:
  nginx:
      image: 607167.dkr.ecr.ap-southeast-1.amazonaws.com/nginx:1
      cpu_shares: 50
      mem_limit: 134217728
      ports:
          - "80:80"
      links:
          - phpfpm
  phpfpm:
      image: 60547.dkr.ecr.ap-southeast-1.amazonaws.com/phpinfo:latest
      cpu_shares: 50
      mem_limit: 134217728
      ports:
          - "9000:9000"
          - "3306:3306"

我尝试将此行添加到yml文件中的两个容器中,但是然后我的容器无法加载.

I tried add this line to both containers in yml file but then my containers fail to load.

  volumes:
      - .:/var/www/html

请帮助.谢谢

推荐答案

我想发布此答案,希望对其他人有所帮助.我花了一天的时间来弄清楚如何解决这种情况,但是解决方案非常简单.

I would like to post this answer in hope that that it will help someone else.I spent a day trying to figure out how to solve this situation BUT the solution was very simple.

与其使用两个单独的容器ONE FOR php 和一个用于 nginx 的容器,不如使用 PHP NGINX 和您的应用

Instead of having two separate containers ONE FOR php and ONE FOR nginx, build a single container with PHP, NGINX and your app

将docker容器视为一个linux vm实例.单个vm可以运行多个服务,单个docker容器也可以运行.每个服务不必位于不同的容器中.

Consider docker containers just as a single linux vm instance. A single vm can have multiple services running, so can a single docker container. Each service does not have to be in the different container.

如果概念清晰,答案很容易.我的不幸并非如此.

Answer was easy if concepts are clear. Mine were not unfortunately.

希望有帮助.

这篇关于在Docker容器中的phpfpm和nginx之间共享应用程序文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:06