A finely tuned engine for deploying blazing-fast Laravel Octane applications. It combines the raw power of Octane with the streamlined efficiency of Docker and Docker Compose to create a production-ready environment that's ready to launch.
- Octane-Optimized: Built specifically to harness the performance gains of Laravel Octane, whether you prefer FrankenPHP, Swoole or RoadRunner.
- Production-Ready Docker Compose: A comprehensive Docker Compose file orchestrates a full stack, including:
- Traefik: Intelligent reverse proxy for routing, load balancing, and secure access.
- PostgreSQL: Robust and reliable database backend.
- Redis: Lightning-fast caching for improved response times.
- Minio: Scalable object storage for your application's assets.
- Typesense: Powerful search engine to enhance user experience.
- pgAdmin & pghero: Tools for database management and performance monitoring.
- Backup Service: Automated backups to protect your valuable data.
- System Monitoring: Glances and Netdata provide real-time insights into your infrastructure.
- Security Hardened: Includes best practices for security, such as user authentication for exposed services and restricted container privileges.
- PHP Powerhouse: Uses official PHP images (Debian or Alpine based) with pre-configured PHP runtime, JIT compiler, and OPcache for maximum performance.
Easily launch your container in different modes to handle specific tasks:
Mode | CONTAINER_MODE value |
Description |
---|---|---|
HTTP Server (default) | http |
Runs your Laravel Octane application. |
Horizon | horizon |
Manages your queued jobs efficiently. |
Scheduler | scheduler |
Executes scheduled tasks at defined intervals. |
Worker | worker |
A dedicated worker for background processing. |
Reverb | reverb |
Facilitates real-time communication with Laravel Echo. |
- Docker installed on your system
- Docker Compose installed on your system
- Setup Laravel Octane, Laravel Horizon and Laravel Reverb
- Clone the repository:
git clone --depth 1 [email protected]:exaco/laravel-octane-dockerfile.git
-
Copy the contents of the cloned directory, including the following items, into your Laravel project powered by Octane:
deployment
directory<your-octane-driver>.Dockerfile
.dockerignore
-
Change the directory to your Laravel project
-
Build your image:
docker build -t <image-name>:<tag> -f <your-octane-driver>.Dockerfile .
# HTTP mode
docker run -p <port>:8000 --rm <image-name>:<tag>
# Horizon mode
docker run -e CONTAINER_MODE=horizon --rm <image-name>:<tag>
# Scheduler mode
docker run -e CONTAINER_MODE=scheduler --rm <image-name>:<tag>
# Reverb mode
docker run -e CONTAINER_MODE=reverb --rm <image-name>:<tag>
# HTTP mode with Horizon
docker run -e WITH_HORIZON=true -p <port>:8000 --rm <image-name>:<tag>
# HTTP mode with Scheduler
docker run -e WITH_SCHEDULER=true -p <port>:8000 --rm <image-name>:<tag>
# HTTP mode with Scheduler and Horizon
docker run \
-e WITH_SCHEDULER=true \
-e WITH_HORIZON=true \
-p <port>:8000 \
--rm <image-name>:<tag>
# HTTP mode with Scheduler, Horizon and Reverb
docker run \
-e WITH_SCHEDULER=true \
-e WITH_HORIZON=true \
-e WITH_REVERB=true \
-p <port>:8000 \
--rm <image-name>:<tag>
# Worker mode
docker run \
-e CONTAINER_MODE=worker \
-e WORKER_COMMAND="php /var/www/html/artisan foo:bar" \
--rm <image-name>:<tag>
# Running a single command
docker run --rm <image-name>:<tag> php artisan about
To deploy your application stack with Docker Compose:
- Copy the following items to your code base:
docker-compose.production.yml
.env.production
Makefile
- Edit
.env.production
and populate it with the appropriate values for your production environment variables (e.g., database credentials, API keys). - Run the following command in your project root directory to prevent permission issues:
sudo mkdir -p storage/framework/{sessions,views,cache,testing} storage/logs && sudo chmod -R a+rw storage
- Run the command
make up
to start the containers.
Note
The included Makefile
offers a range of additional commands for managing your deployment, including options for rebuilding, stopping, and restarting services.
Caution
Do not forget to edit .env.production
!
- You can use the
APP_ENV
build argument to specify a different environment file.
// config/octane.php
return [
'swoole' => [
'options' => [
'http_compression' => true,
'http_compression_level' => 6, // 1 - 9
'compression_min_length' => 20,
'package_max_length' => 2 * 1024 * 1024, // 2MB
'upload_max_filesize' => 20 * 1024 * 1024 // 20MB
'open_http2_protocol' => true,
'document_root' => public_path(),
'enable_static_handler' => true,
]
]
];
- Some configurations are highly opinionated, so please make sure they align with your needs.
- Laravel Octane logs request information only in the
local
environment. - Be mindful of the contents of the
.dockerignore
file.
- Add Docker Compose
- Add support for PHP 8.4
- Add support for worker mode
- Build assets with Bun
- Install more Caddy modules
- Create standalone and self-executable app
- Add support for Horizon
- Add support for RoadRunner
- Add support for FrankenPHP
- Add support for Laravel Reverb
- Add support for the full-stack apps (Front-end assets)
- Add support
testing
environment and CI - Add support for the Laravel scheduler
- Add support for Laravel Dusk
- Support more PHP extensions
- Add tests
- Add Alpine-based images
Thank you for considering contributing! If you find an issue, or have a better way to do something, feel free to open an issue, or a PR.
This repository is open-sourced software licensed under the MIT license.