Laravel Docktane Documentation

repository·main·Indexed 21 days ago

https://github.com/exaco/laravel-docktane

A 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.

Tokens
1.5K
Snippets
4
Records
6
Agent score
26%

What's inside Laravel Docktane

  1. Overview of Laravel Docktane

    main
    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.
  2. Configure Container Modes via `CONTAINER_MODE`

    main

    You can launch your container in different modes by setting the CONTAINER_MODE environment variable. This allows a single image to serve different roles in your infrastructure.

    ModeCONTAINER_MODE valueDescription
    HTTP ServerhttpRuns your Laravel Octane application (default).
    HorizonhorizonManages your queued jobs efficiently.
    SchedulerschedulerExecutes scheduled tasks at defined intervals.
    WorkerworkerA dedicated worker for background processing.
    ReverbreverbFacilitates real-time communication with Laravel Echo.
    Inertia SSR ServerssrRuns the Inertia SSR server with bun runtime.
  3. Deploy the full stack with Docker Compose

    main

    For a complete production environment (including PostgreSQL, Redis, Horizon, Scheduler, Monitoring, etc.), use the provided compose.production.yaml.

    1. Copy compose.production.yaml, .env.production, and Makefile to your project root.
    2. Crucial: Edit .env.production and populate it with your production environment variables (database credentials, API keys, etc.).
    3. Run the deployment command:
      make up

    The Makefile also provides commands for rebuilding, stopping, and restarting services.

    # Deployment steps
    cp compose.production.yaml .env.production Makefile .
    # Edit .env.production first!
    make up
  4. Set up Laravel Docktane in your project

    main

    To use Laravel Docktane, follow these steps to integrate its files into your existing Laravel Octane project:

    1. Clone the repository:
      git clone --depth 1 git@github.com:exaco/laravel-docktane.git
    2. Copy the following items from the cloned directory into your Laravel project root:
      • deployment/ directory
      • <your-octane-driver>.Dockerfile (e.g., Swoole.Dockerfile)
      • .dockerignore
    3. Navigate to your Laravel project directory.
    4. 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 .
  5. Run Docker containers in different modes

    main

    Use the docker run command 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
  6. Configure Octane settings for production

    main

    When using Swoole, it is recommended to optimize your config/octane.php for 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,
    ];