dream0776 2016-04-30 03: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 04: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 为什么树莓派5b显示禁止连接
  • ¥20 流量太费!寻找便宜的app音视频SDK或平替方案。
  • ¥15 kubeasz部署遇到问题
  • ¥15 GUIDE to App Designer Migration Tool for MATLAB
  • ¥50 第三代非支配排序遗传算法(NSGA-Ⅲ)和多目标粒子群优化算法(MOPSO)的实现
  • ¥20 plant simulation与python com接口实时数据交互
  • ¥15 有关汽车的MC9S12XS128单片机实验
  • ¥15 求c语言动态链表相关课程有偿,或能将这块知识点讲明白
  • ¥15 FLKT界面刷新异常
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部