This directory houses your Laravel application.
- Laravel + Octane
- PostgreSQL
- Redis
- Mailpit (SMTP server)
- Minio (S3 compatible server)
The installation process involves creating a shared network, building images, and initializing a new Laravel application. Execute the following script in your terminal to automate the entire process:
./install.sh
This script installs a Laravel app along with Octane and S3 packages.
Now you should be able to see it running in your browser at http://localhost:8000.
There are own docker compose file for each environment: production, local, and testing. For local development it could be useful to rename a compose.local.yaml
file to compose.yaml
. This allows to run docker compose command without having to specify the specific compose file.
For example, to build images for local environment, use the following command:
docker compose -f compose.local.yaml build
docker compose -f compose.local.yaml up
Now you can open http://localhost:8000 URL in your browser.
docker compose -f compose.local.yaml down
For artisan commands, specify the current user to ensure correct file permissions. For example, to generate a Product
model:
docker compose -f compose.local.yaml exec --user $(id -u):$(id -g) app php artisan make:model Product
The Mailpit service intercepts all sent emails by your application in the local environment.
If you want to check how sent mails look, just go to http://localhost:8025 in your browser.
Use compose.testing.yaml
for testing. This environment is simpler than the local setup as it doesn't require a separate web server, queue worker, allowing us to use drivers like "sync" for the queue and "array" for the cache.
It features a separate database with an in-memory volume for improved performance during database-dependent tests.
Start the testing environment with:
docker compose -f compose.testing.yaml up -d
Then we can execute tests really quick like this:
docker compose -f compose.testing.yaml exec app vendor/bin/phpunit
For convenience create a useful bash alias like this:
alias t="docker compose -f compose.testing.yaml exec app vendor/bin/phpunit"
Then you can run tests by simply using these commands:
# Run all tests
t
# Run tests with filter by "ProductTest"
t --filter ProductTest
# Run tests from Unit suite
t --testsuite Unit
All laravel logs are forwarded to the docker log collector via the stderr
channel.
See the latest logs running the command:
docker compose -f compose.local.yaml logs
The best alternative to this is the official Laravel Sail tool which is intended for development environment only.
Sail is automatically installed with all new Laravel applications.
Also, there is an excellent project called Laradock that contains a full bunch of services.
- use php.ini-development & php.ini-production from base php image
- replace octane watcher with
docker compose watch
for app, queue, schedule services