I am in the process of dockerizing a laravel stack application.
i have a service called app
that's running php-fpm
and includes the laravel source code inside it.
i want to replicate this service so i can benefit from high-availablity and zero down-time features.
I do not know how to deal with OPcache:
app
container?if so this approach reserves plenty of server's memoryapp
service on the same docker machine ?Whenever the script compiles, the process checks the PHP OPcode caching and finds the already compiled code on shared memory. If the code is not found, initiates the compilation automatically and saves that to the memory generating output after that.
So now we can discuss your question based on the above flow of Opcache
should i run opcache optimize in every app container? if so this approach reserves plenty of server's memory
Yes you should run OpCache in every container as each container running on its own space, second thing It will save plenty of your container memory otherwise without OpCache your container will be failed to respond in case of the heavy load.
Both tests reported about 50% decrease in response time after installing OpCache.
opcache-configuration-to-avoid-caching-suprises
Is there any way to share opcache between tasks(containers) of app service on the same docker machine ?
The first thing one container can not access the memory of another container without high privileged and for that you need extra configuration, Second thing One should avoid doing this, container are designed to run independently and manage a single process per container ( rule of thumb).
assume that's possible , is this approach correct this sort of problems or its considered as anti pattern ?
No, In Docker container it discouraged and container should be decoupled.
In general, a decoupled architecture is a framework for complex work that allows components to remain completely autonomous and unaware of each other. Cloud computing is sometimes said to have a decoupled architecture because the cloud provider manages the physical infrastructure, but not the applications or data hosted on it.