Docker Community Forums

Share and learn in the Docker community.

First time using docker?

Hi all,

I have a PHP application (around 2000 files) i want to create a container of my php app, so i can use services like NGINX Plus to make it scalable, more secure, use kubernetes etc.

My main question is the following.
What is needed (in terms of code -php) to containerize the app and make it scalable?

Is there any way that I will not be able to create a package because of the PHP code? are there any restrictions?
My webapp is a pure php app, with no frameworks.

Hi. The difference is mainly not how your PHP works but how your compontents interacts with eachother. Usually TCP sockets / API calls instead of unix sockets. You also avoid storing anything to the container’s filesystem and use bind mounts or volumes but this is not related to PHP in any way.

On the otehr hand, since a container usually has less privileges, you might have some permission issues if you don’t configure your container properly.

To make your PHP app scalable you have to make sure your containers’ state are stored outside the container. You can use redis for sessions and and external databases to store data. If you also have data on the filesystem, make sure all of your container instances can read it and the shared filesystem supports locks if the containers try to write the same data. I think this is the hardest part since you have to find the proper filesystem which you can learn enough to be able to maintain it.

The other way would be to replicate your application’s data between your containers as databases do but I don’t think it is a common solution with PHP.

I can’t tell you more without a more specific question.

Hi, thanks for taking the time to reply.

What do you mean by components? I am not using the “microservices” architecture, so the whole app will be one container. Files are generated,created dynamically depending on the user’s actions and they are saved on a specific folder within the webapp’s files.

I am not very worried about the scalability and permissions issues, because NGINX Plus told me that they just need the PHP App in a container and they will manage everything else.

So my main concern is still if there are there any specific requirements for this concept to work? I mean will the PHP app require any code changes for this to work?

Is there a chance that docker will fail to containerize the php app for a specific reason?

(I will try to create a container with the current php files, during the christmas holidays until i learn/read more about docker)

Scalability usualy doesn’t come for free… All parts of the processing chain must be able to handle it properly.

Lets assume your application depends on the session state: 1st request ends in replica1, 2nd request ends up in replica2… how does the 2nd replica know about the session state of replica1? Hint: Akos made suggestions on how to externalize session state.

Lets ignore the session state and take a look on the generated files: 1st request ends in replica1 and creates a file, 2nd request end up in replica2 and neds to access the file created by replica1? How is this done? Lets asume you use a remote file share like nfs, what happens in severall replicas try to write the same file or read incoplete files ? Is there some file locking in place?

Docker does whatever a creater/maintainer of a Dockerfile uses to build the image. Everything needs to be fully automated: installation and configuration of dependencies and runtimes, integration and configuration of your own artifacts. Typicaly an entrypoint scripts need to be created, that leverages container environment variables to override configuration values in configuration files - at least for environment specific third party endpoints like database connections or other services needed from the applciation.

Make sure you properly understand what part of “scalling / load distribution” nginx actualy is responsible for and what parts it needs you to have implemented in the behavior of your application.