Simple docker-compose for Laravel, with postgresql, redis, nginx and php-fpm
- Docker running on the host machine.
- Docker compose running on the host machine.
- Basic knowledge of Docker.
- To get started, the following steps needs to be taken:
- Clone the repo.
cd docker-laravel-postgres-nginxto the project directory.cdto web and run the command to create a new Laravel project into application directory.cd ..to back the project directory.cp .env.example .envto use env config file- Edit
.envand setPHP_VERSIONto the desired PHP release (e.g. 7.4, 8.1) - Run
docker-compose up -dto start the containers. - Visit http://localhost to see your Laravel application.
- Try to connect 127.0.0.1:5432 to access Postgres
- After starting, note that one directory and one file will be created with name postgres and file data, this files are Database archives
docker-compose up -dto start all containersdocker-compose downto stop all containers- If you need to restart after modifying docker-compose.yml restart with
docker-compose downanddocker-compose up -d - Run
pytestto execute the tests
-
redis:alpine
-
postgres:9.5-alpine
-
nginx:alpine
-
php-fpm image according to
PHP_VERSIONin.env
- Dockerfile installs
pgsqlandgdfor the configured PHP version along withphp-redis - php-ini-overrides.ini
- file conf nginx
- nginx folder
- php-ini-overrides.ini
- data(postgres)
- create file conf of nginx in nginx directory you should use default.conf as example
- restart containers:
docker-compose downanddocker-compose up -d
- Verify all containers running:
docker ps -a - Stop all containers and remove:
docker stop $(docker ps -a -q)anddocker rm $(docker ps -a -q) - Try to start again
docker-compose up -d