Laravel Docktane Documentation
repository·main·Indexed 21 days ago
https://github.com/exaco/laravel-docktaneA production-ready Docker orchestration toolset for Laravel applications running on Laravel Octane. It provides optimized Dockerfiles for Swoole, RoadRunner, and FrankenPHP drivers, along with a complete Docker Compose stack for production deployments including databases, caching, monitoring, and search services. Supports multiple container modes via the CONTAINER_MODE environment variable, including HTTP server, Horizon, Scheduler, Worker, Reverb, and Inertia SSR.
What's inside Laravel Docktane
- Laravel Docktane provides a production-ready Docker setup for running high-performance Laravel applications using Laravel Octane. It includes Dockerfiles for various Octane drivers (Swoole, RoadRunner, and FrankenPHP) and a comprehensive Docker Compose configuration for orchestrating a full application stack, including databases, caching, monitoring, and search services.
Configure Container Modes via `CONTAINER_MODE`
mainYou can launch your container in different modes by setting the
CONTAINER_MODEenvironment variable. This allows a single image to serve different roles in your infrastructure.Mode CONTAINER_MODEvalueDescription HTTP Server httpRuns your Laravel Octane application (default). Horizon horizonManages your queued jobs efficiently. Scheduler schedulerExecutes scheduled tasks at defined intervals. Worker workerA dedicated worker for background processing. Reverb reverbFacilitates real-time communication with Laravel Echo. Inertia SSR Server ssrRuns the Inertia SSR server with bunruntime.Deploy the full stack with Docker Compose
mainFor a complete production environment (including PostgreSQL, Redis, Horizon, Scheduler, Monitoring, etc.), use the provided
compose.production.yaml.- Copy
compose.production.yaml,.env.production, andMakefileto your project root. - Crucial: Edit
.env.productionand populate it with your production environment variables (database credentials, API keys, etc.). - Run the deployment command:
make up
The
Makefilealso provides commands for rebuilding, stopping, and restarting services.# Deployment steps cp compose.production.yaml .env.production Makefile . # Edit .env.production first! make up- Copy
Set up Laravel Docktane in your project
mainTo use Laravel Docktane, follow these steps to integrate its files into your existing Laravel Octane project:
- Clone the repository:
git clone --depth 1 git@github.com:exaco/laravel-docktane.git - Copy the following items from the cloned directory into your Laravel project root:
deployment/directory<your-octane-driver>.Dockerfile(e.g.,Swoole.Dockerfile).dockerignore
- Navigate to your Laravel project directory.
- Build your image using the specific driver Dockerfile:
docker build -t <image-name>:<tag> -f <your-octane-driver>.Dockerfile .
git clone --depth 1 git@github.com:exaco/laravel-docktane.git # Copy deployment/, <driver>.Dockerfile, and .dockerignore to your project docker build -t my-app:latest -f Swoole.Dockerfile .- Clone the repository:
Run Docker containers in different modes
mainUse the
docker runcommand with environment variables to control the container's behavior.Standard Modes:
- HTTP mode (default):
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> - SSR mode:
docker run -e CONTAINER_MODE=ssr --rm <image-name>:<tag>
Combined HTTP mode with extra services:
- With Horizon:
docker run -e WITH_HORIZON=true -p <port>:8000 --rm <image-name>:<tag> - With Scheduler:
docker run -e WITH_SCHEDULER=true -p <port>:8000 --rm <image-name>:<tag> - With Scheduler, Horizon, Reverb, and SSR:
docker run \ -e WITH_SCHEDULER=true \ -e WITH_HORIZON=true \ -e WITH_REVERB=true \ -e WITH_SSR=true \ -p <port>:8000 --rm <image-name>:<tag>
Worker mode: Specify a custom command for the worker using
WORKER_COMMAND:docker run -e CONTAINER_MODE=worker -e WORKER_COMMAND="php /var/www/html/artisan foo:bar" --rm <image-name>:<tag># Example: Running HTTP mode with Scheduler and Horizon enabled docker run \ -e WITH_SCHEDULER=true \ -e WITH_HORIZON=true \ -p 8000:8000 \ --rm my-app:latest- HTTP mode (default):
Configure Octane settings for production
mainWhen using Swoole, it is recommended to optimize your
config/octane.phpfor production. Key settings include compression, file upload limits, and state file management.// 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, ] ], // Required for certain Octane operations 'state_file' => base_path('bootstrap/octane-server-state.json'), // Recommended for performance/stability 'usleep_between_writing_server_output' => 1, ];// config/octane.php return [ 'swoole' => [ 'options' => [ 'http_compression' => true, 'http_compression_level' => 6, 'compression_min_length' => 20, 'package_max_length' => 2 * 1024 * 1024, 'upload_max_filesize' => 20 * 1024 * 1024, 'open_http2_protocol' => true, 'document_root' => public_path(), 'enable_static_handler' => true, ] ], 'state_file' => base_path('bootstrap/octane-server-state.json'), 'usleep_between_writing_server_output' => 1, ];