Skip to content

Production-ready Dockerfile for Laravel Octane powered web services and microservices. Done right.

License

Notifications You must be signed in to change notification settings

avrabel-work/laravel-octane-dockerfile

Repository files navigation

Laravel Octane Dockerfile

LicenseGitHub release (latest by date)GitHub closed pull requestsGitHub Workflow StatusGitHub Workflow Status

A pretty configurable, production-ready, and multi-stage Dockerfile for Laravel Octane powered web services and microservices.

The Docker configuration provides the following setup:

  • PHP 8.1 and 8.2 official DebianBookworm-based images
  • Preconfigured JIT compiler and OPcache

Container modes

You can build the Docker image in different modes:

ModeCONTAINER_MODE ARGHTTP serverExposed port
Octane (default)appSwoole / RoadRunner9000
Horizonhorizon--
Schedulerscheduler--

If you want to run Horizon in the Octane container, then you should set APP_WITH_HORIZON build argument true.

If you want to run Scheduler in the Octane container, then you should set APP_WITH_SCHEDULER build argument true.

Usage

  1. Clone this repository:
git clone --depth 1 [email protected]:exaco/laravel-octane-dockerfile.git 
  1. Copy cloned directory content including deployment directory, Dockerfile, and .dockerignore into your Octane powered Laravel project
  2. Change the directory to your Laravel project
  3. Build your image:
  • Container app mode:
docker build -t <image-name>:<tag> . 
  • Container horizon mode:
docker build -t <image-name>:<tag> --build-arg CONTAINER_MODE=horizon . 
  • Container scheduler mode:
docker build -t <image-name>:<tag> --build-arg CONTAINER_MODE=scheduler . 
  1. Up the container:
docker run -p <port>:9000 --rm <image-name>:<tag> 

Configuration

There is something that you maybe want to configure:

  • Swoole HTTP server config in supervisord.app.conf
  • PHP configurations in php.ini
  • ENTRYPOINT Bash script in entrypoint.sh
  • Set PHP_VERSION using the --build-arg option along with the build command
  • Set TZ (OS timezone) using the --build-arg option along with the build command

Using RoadRunner instead of Swoole

  1. Ensure you have roadrunner as a dependency in your composer.json
  2. Set OCTANE_SERVER=roadrunner using the --build-arg option along with the build command

You can configure RoadRunner through deployment/octane/.rr.prod.yaml.

Recommended Swoole options for octane.php

// config/octane.phpreturn [ 'swoole' => [ 'options' => [ 'http_compression' => true, 'http_compression_level' => 6, // 1 - 9'compression_min_length' => 20, 'package_max_length' => 20 * 1024 * 1024, // 20MB'open_http2_protocol' => true, 'document_root' => public_path(), 'enable_static_handler' => true, ] ] ];

Utilities

Also, some useful Bash functions and aliases are added in utilities.sh that maybe help.

Notes

  • Laravel Octane logs request information only in the local environment.
  • Please be aware of .dockerignore content

ToDo

  • Add support for Horizon
  • Add support for RoadRunner
  • 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

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.

About

Production-ready Dockerfile for Laravel Octane powered web services and microservices. Done right.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dockerfile80.4%
  • Shell19.6%