I have a php docker container, that runs my app, and I need to start using Composer to install a php package. What is the best way to approach it?
Source files can be found here:
https://github.com/ikknd/docker-study in folder recipe-05
Technically this works, I get composer installed in my php image, and whenever I need to update or install dependencies I simply execute calls in my custom php container.
Problems:
I will use ideas from recipe 02 - simple php page, and recipe 04 - redis setup.
Create docker-compose.yml file in "docker" folder:
Here I do several things:
The goal here is to use composer library - "predis/predis" (just as an example). This library needs to get installed once "composer" container gets started.
I can go to /var/www/docker-study.loc/recipe-05/docker/ and execute:
docker-compose up -d
Now go to myapp.loc/ and see "works!"
When composer container started, it executed "composer install" command and then exited. I can confirm this by running: "docker container ls -a" - this will show that container "docker_composer_1" has exited.
If I do - "docker logs docker_composer_1" - I can see information on what happened when container started, and how "composer install" process went.
What if I change composer.json file, and need to install additional library?
docker-compose restart composer
This will start this container again, execute install and exit.
What if I need to run "composer update" instead of "composer install"?
I can change "install" -> "update" in docker-compose.yml, and run "docker-compose restart composer"