exaco/laravel-docktane
À propos
Configuration Docker prête pour la production pour les services web et microservices basés sur Laravel. Bien conçue.
Développement web et applicatifWhat you can do
- Multiple Drivers: Dockerfiles available for Swoole, RoadRunner, and FrankenPHP.
- Production-Ready: Optimized for a production environment with best practices.
- Container Modes: Easily run your container in different modes for handling web requests (http), queues (horizon), scheduled tasks (scheduler), custom worker (worker), WebSocket server (reverb), or Inertia SSR server (ssr).
- Extensible: Simple to customize for your specific application needs.
Progression mesurée des étoiles
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalLaravel Docker Setup
A production-ready Docker setup for running high-performance Laravel applications with Laravel Octane. This repository provides Dockerfiles and a comprehensive Docker Compose configuration for various Octane drivers, including Swoole, RoadRunner, and FrankenPHP.
Key Features
- Multiple Drivers: Dockerfiles available for Swoole, RoadRunner, and FrankenPHP.
- Production-Ready: Optimized for a production environment with best practices.
- Container Modes: Easily run your container in different modes for handling web requests (
http), queues (horizon), scheduled tasks (scheduler), custom worker (worker), WebSocket server (reverb), or Inertia SSR server (ssr). - Extensible: Simple to customize for your specific application needs.
- Comprehensive Docker Compose: Includes a production-ready
compose.production.yamlto orchestrate the full application stack.
Container modes
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. |
| Inertia SSR Server | ssr |
Runs the Inertia SSR server with bun runtime. |
Production-Ready Docker Compose
For a complete production environment, this repository includes a compose.production.yaml file to orchestrate a full stack of services. This setup is security-hardened and provides a comprehensive solution for deploying and managing your application.
The orchestrated containers include:
- Application: Your Laravel Octane application running in http mode to serve web requests.
- Horizon: A dedicated container for running Laravel Horizon to manage your Redis queues.
- Scheduler: A container responsible for executing Laravel's scheduled tasks.
- Database: A PostgreSQL container for your application's database.
- PgBouncer: Lightweight connection pooler for PostgreSQL.
- Redis: An in-memory data store used for caching and as a message broker for Laravel Horizon.
- RustFS: RustFS is a high-performance, distributed object storage system built in Rust.
- Typesense: A fast, typo-tolerant, and open-source search engine for building powerful search functionality into your application.
- pgAdmin & pghero: Web-based tools for managing your PostgreSQL database and monitoring its performance.
- Backup Service: A container that performs automated backups of your database to ensure data safety.
- System Monitoring: Includes Netdata containers to provide real-time insights and monitoring for your entire infrastructure.
- Prometheus: A powerful time-series database used for collecting metrics from your application and the host system.
- Grafana: A leading open-source platform for monitoring and observability, used to visualize the metrics collected by Prometheus in beautiful dashboards.
This comprehensive stack provides a robust and observable environment for your production application.
Prerequisites
- Docker installed on your system
- Docker Compose installed on your system
- Setup Laravel Octane, Laravel Horizon and Laravel Reverb
Usage
Building Docker image
- Clone the repository:
git clone --depth 1 [email protected]:exaco/laravel-docktane.git
Copy the contents of the cloned directory, including the following items, into your Laravel project powered by Octane:
deploymentdirectory<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 .
Running Docker container
# 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>
# SSR mode
docker run -e CONTAINER_MODE=ssr --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, 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
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
Docker Compose
To deploy your application stack with Docker Compose:
- Copy the following items to your code base:
compose.production.yaml.env.productionMakefile
- Edit
.env.productionand populate it with the appropriate values for your production environment variables (e.g., database credentials, API keys). - Run the command
make upto start the containers.
[!NOTE]
The includedMakefileoffers 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!
Configuration and Customization
- You can use the
APP_ENVbuild argument to specify a different environment file.
Octane workers
In http mode, these environment variables set the matching options of the Octane server command:
| Variable | Default | Option | Servers |
|---|---|---|---|
OCTANE_WORKERS |
auto |
--workers |
FrankenPHP, Swoole, RoadRunner |
OCTANE_TASK_WORKERS |
auto |
--task-workers |
Swoole |
OCTANE_MAX_REQUESTS |
500 |
--max-requests |
FrankenPHP, Swoole, RoadRunner |
The defaults are Octane's own. A variable that is unset or empty takes its default.
auto sizes the pool from the CPUs the container can see: two workers per CPU with FrankenPHP (from the cgroup CPU quota when one is set, otherwise the host's CPUs), one per CPU with Swoole and RoadRunner. Each worker keeps a booted application in memory and, once it has used the database, an open connection. On a large host, or behind a connection limit, set a fixed number:
docker run -e OCTANE_WORKERS=4 -p <port>:8000 --rm <image-name>:<tag>
Set these variables in the container's environment (docker run -e, environment: in Compose), not in .env.production: supervisord reads them before Laravel loads its environment file.
Recommended options in octane.php
// 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,
]
],
// https://github.com/laravel/octane/pull/853#issuecomment-1999530137
'state_file' => base_path('bootstrap/octane-server-state.json'),
// https://github.com/laravel/octane/pull/902/files
'usleep_between_writing_server_output' => 1,
];
Essential Notes
- Some configurations are highly opinionated, so please make sure they align with your needs.
- Laravel Octane logs request information only in the
localenvironment. - Be mindful of the contents of the
.dockerignorefile.
ToDo
- 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
testingenvironment and CI - Add support for the Laravel scheduler
- Add support for Laravel Dusk
- Support more PHP extensions
- Add tests
- Add Alpine-based images
Contributing
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.
Credits
License
This repository is open-sourced software licensed under the MIT license.
Explorer des projets similaires
Chargement…