dream0776 2016-04-30 11:51
浏览 93
已采纳

使用docker的多个nginx / php应用程序的体系结构

I've been running most of my apps on single nginx/php-fpm installation directly on vps. I've decided to try out docker, and have been playing with it for a week now. I've read everything possible and believe I understand its concepts.

But I cannot wrap my head around having so many instances of nginx, php and db.

One thing I settled with is that I want to have 1 db, so that's easy:

mariadb:
  image: mariadb:latest
  container_name: mariadb
  ports:
    - "127.0.0.1:3306:3306"
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: xxxxx
  volumes:
    - /srv/mysql:/var/lib/mysql

I also found nginx-proxy together with nginx-certs work like charm:

nginx-proxy:
  image: jwilder/nginx-proxy
  container_name: nginx-proxy
  ports:
    - "80:80"
    - "443:443"
  restart: always
  volumes:
    - /srv/certs:/etc/nginx/certs:ro
    - /var/run/docker.sock:/tmp/docker.sock:ro
    - ./vhost.d:/etc/nginx/vhost.d
    - /usr/share/nginx/html


nginx-certs:
  image: jrcs/letsencrypt-nginx-proxy-companion
  container_name: nginx-certs
  volumes:
    - /srv/certs:/etc/nginx/certs:rw
    - /var/run/docker.sock:/var/run/docker.sock:ro
  volumes_from:
    - nginx-proxy

This is all dandy. But how do I handle actual app containers?

I want to keep ram usage to minimum, so what is recommended:

  1. 1 php-fpm container with multiple volumes inside and multiple nginx servers
  2. 1 nginx server and multiple php-fpm containers?
  3. have 1 container per project and keep nginx/php-fpm inside that container
  4. X nginx containers + X php-fpm containers. X amount of apps.

Any ideas?

  • 写回答

2条回答 默认 最新

  • dongyi7041 2016-04-30 12:16
    关注

    You should only need 1 nginx container per host, and use that to load balance between your php containers. If you set the restart policy correctly on the nginx container, it should always be running, and nginx can handle a lot of load, so only one should be fine.

    It also gets harder to manage when you have more than one nginx, since only one container can bind to ports 80 and 443 at a time, and you would need something in front of the two nginx containers to load balance between them in that case. If you want redundancy you can add another host with that same exact setup, the load balance between the hosts.

    1 db container with volumes for the data is good.

    At least 1 php container, ideally more than one, but depends on your load. If you plan on changing the data(php files) in the containers (not recommended) when running, then make sure you use a volume, and share between all php containers.

    Have nginx load balance between the php containers, and make sure the restart policy for the php containers are setup correctly.

    If you need to update the php container images, it makes it easier if you have more than one, then you can do a rolling upgrade with no downtime.

    1. Pull down new image
    2. Stop php1 container, start with new image
    3. Stop php2 container, start with new image

    Done, rolling upgrade with no downtime.

    This setup works with one site, or many. The only difference is that nginx would be handling the proxying to the correct php containers based on the hostname.

    So you would always have 1 nginx, but the php containers would grow based on the number of sites you are hosting.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog