Docker - Execute a PHP from a different container than my PHP-FPM container

Viewed 163

Hello stack overflow !

TL:DR i try to execute a php command in a container that pull my git repo and have not PHP, but is linked to my PHP container that i used as an engine for different projects.

So here is my issue.

I have a docker web stack for my production server composed by :

  • Nginx container in front
  • PHP-FPM 7.4 container as engine for 1 project
  • PHP-FPM 7.2 container as engine for 2 project
  • 3 "Git" container that sync my git repo to get the different php symfony project (1 for each)

Today, i used the "Git" container to dl the code, throw it into a directory shared with the PHP and Nginx container.

Then i php composer to DL the vendor of my project with a docker exec php on the good container and i am ready to go.

I want to automatise this in my Git container, so when i start it, he pull, install the vendor, run some php script to check the project is working, and we are done.

Problem; despite being linked to the PHP container i am not able to use the PHP command (which is normal).

The only solution i found, is to install docker-cli in my Git container, share the docker socket with it, so i can use docker exec in my container.

I found this solution not very effective to be honest, particularly because i have access to php container through the link. And i am worried this could create some security issue. NGINX is working with the solution of calling the php container with a socket, if i understand correctly, and this is working like a charm.

So for me the idea, would be to "create" a php.bash in my Git container, that will just call the PHP container linked to it to execute php inside my Git container. But despite my different search i dont find any clue on how to do that.

Before asking:

  • I dont want PHP installed inside my Git container for a few reason, one of them is the space i have on the server and one other is the fact that i will use one version of PHP for 3 project in a near future.
  • I dont want to have git installed inside my PHP container, because i want that Git container to be a option for automated deployment in a near futur to.

I hope i explain this correctly, and if it is not clear, feel free to ask ;)

Thank you for the time you take to read this, hope someone can help me.

0 Answers
Related