Answer the question
In order to leave comments, you need to log in
How to connect web service docker container(php-fpm+nginx) to code docker container(php) using socket(socket)?
Hello!
Please help me with the next question.
Docker was used to develop php projects on local machines. Now we decided to try to transfer to Docker - stage and production.
Plus, there was a desire to try to implement the deployment process itself using Docker, without third-party tools like Capistrano, etc.
The simplest deployment mechanism assumed the following:
- an "empty" Docker-image is assembled, which includes the project files, let's call it App. It is intended only for storing and transporting project files.
- using Docker-Compose and Docker-Machine, a Docker-container based on App-image is launched on a remote machine.
— access of the web service container (php-fpm+nginx) to the project files from the App container is carried out via named-volume.
Tried. Works. But it only works for the initial launch of the project. Since providing access to the project code through named-volume has its own nuances. I only found out about them after I opened issues on Docker github. I started building my crutches with named-volume cleanup, etc. Realized that this is not the true-docker-way. Decided to drop this option.
On Docker github , they suggested linking Web(php-fpm+nginx) and App(php-code) containers using socket.
Actually, the question is how to do it correctly in the context of Docker.
Thanks a lot for your help and advice!
Answer the question
In order to leave comments, you need to log in
In your case, php-fpm should be moved to the container with the code (app). Options to make it available to nginx 2:
- via tcp port
- via socket located in the volume of the image (for example, in Dockerfile: VOLUME /var/run/sockets/
), in the nginx container we prescribe --volumes-from app
and listen to the fpm socket in the same folder (/var/run/sockets/) but already in an nginx container.
Personally, I like the tcp approach for php-fpm better because it can be scaled.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question