Sharing app files between phpfpm and nginx in dock

2019-07-26 09:18发布

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

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.

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.

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

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

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"

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

  volumes:
      - .:/var/www/html

Please help. Thanks

1条回答
We Are One
2楼-- · 2019-07-26 09:41

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.

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

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.

Hope it helps.

查看更多
登录 后发表回答