Monday, June 14, 2021

PHP and Laravel project setup in docker compose

 




composer is for php like npm for node.

customized php image with other tools.
if no CMD provided, the base image CMD will be used for running the container.

official docker image of php:
https://github.com/docker-library/php/blob/master/7.4/apline3.12/fpm/Dockerfile
Here 9000 is exposed as seen in php docker file of official repo.

to run an individual service/container:
-------------
docker-compose run --rm composer create-project --prefer-dist laravel/laravel .

this will create a skeleton project code for us in the src folder as we kept bind mount to that folder in composer service section.

After skeleton creation we can stop this service/container.

src/.env:
-----
update database settings here also.

#docker-compose up -d server php mysql
docker-compose up -d --build server 
#php and mysql are mentioned as depends_on so not required to pass.--build the images if any changes in layers.If not provided, will build only if image is not there.

artisan,some php tools, used to populate database with some initial data and some other tools.

#with other services of application running
docker-compose run --rm artisan migrate

if you observe docker-compose.yaml file, we used some dockerfile concepts here, like entrypoint

https://github.com/uday1kiran/dockercompose_php/tree/c3bb075ca33af7d4ab3d029223efd3124a3c7fd6

instead of using the bind mappings, lets use a new docker file for nginx with source code copied.
docker-compose up -d --build server 
docker-compose run --rm artisan migrate 

https://github.com/uday1kiran/dockercompose_php/tree/b9fc4c94adec0bb0f479d90319646af6bec268b4

No comments:

Post a Comment