I was using laravel homestead solution for development but now i would like to migrate to docker. The question is how "bloated" should be my containers. When I say "bloated" I mean how much modules/service should be per container. For example i created four custom containers like this:
php
-> php-fpm
-> composer
-> memcached
-> redis
mysql
-> mysql
nginx
->nginx
node
->gulp
->bower
->npm
->grunt
The question is, if this is right clustering or should i create separate container let say for grunt, bower, memcached etc.? How to decide what goes together and what to separate container? Are there any rules? Should be development the same as production?
How you factor app components into containers depends on what your goals are. Is your goal to make your server easier to manage/administer? Are you primarily interested in how to scale your app successfully as it gets more traffic? Here are some suggestions if scaling is your primary concern:
Here is a diagram to represent this:
Note that you can add as many PHP/Redis/Memcached containers as you would like to handle additional server load as necessary. These containers don't even necessarily have to be on the same physical server, which is where you get added memory and processing power.
If you don't expect the load on your app to be such that you need all of this to manage it, it might just be easier to stick with the traditional approach. Docker is still relatively new and not truly recommended for production environments, although, like me, you're probably really interested in figuring out how it can be useful.
One of the cool things about Docker is that you develop your containers locally and can deploy them "as is" into the cloud. So, locally you'd have all of these containers (and you could even swap out some of them, say your DB and/or server), and then deploying just becomes a matter of running a new instance of your container on the production server.
I hope this helps you understand better how you might come up with a strategy for factoring the pieces of your app into containers. Docker is still relatively new to the Laravel space, and so I'm sure these practices will change rapidly over the next year or two, and probably eventually become automated.
When defining my containers, I always think ahead on how much the specified service will scale, and if I can scale it in an isolated way. So that I can scale specific services at time and fine tune where the bottleneck really is. Using your example I would do:
You can always think on adding more MySQL instances to MySQL cluster the same way you can do with Memcached and Redis.
As ultimate level of advice, on the production environment you should think on using something like Amazon RDS and Amazon Elasticache for both MySQL and Memcached + Redis. This will be way easier to setup and manage.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.