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
You can build the Docker image in different modes:
| Mode | CONTAINER_MODE ARG | HTTP server | Exposed port |
|---|---|---|---|
| Octane (default) | app | Swoole / RoadRunner | 9000 |
| Horizon | horizon | - | - |
| Scheduler | scheduler | - | - |
If you want to run Horizon in the Octane container, then you should set
APP_WITH_HORIZONbuild argumenttrue.
If you want to run Scheduler in the Octane container, then you should set
APP_WITH_SCHEDULERbuild argumenttrue.
- Clone this repository:
git clone --depth 1 [email protected]:exaco/laravel-octane-dockerfile.git - Copy cloned directory content including
deploymentdirectory,Dockerfile, and.dockerignoreinto your Octane powered Laravel project - Change the directory to your Laravel project
- Build your image:
- Container
appmode:
docker build -t <image-name>:<tag> . - Container
horizonmode:
docker build -t <image-name>:<tag> --build-arg CONTAINER_MODE=horizon . - Container
schedulermode:
docker build -t <image-name>:<tag> --build-arg CONTAINER_MODE=scheduler . - Up the container:
docker run -p <port>:9000 --rm <image-name>:<tag> There is something that you maybe want to configure:
- Swoole HTTP server config in
supervisord.app.conf - PHP configurations in
php.ini ENTRYPOINTBash script inentrypoint.sh- Set
PHP_VERSIONusing the--build-argoption along with the build command - Set
TZ(OS timezone) using the--build-argoption along with the build command
- Ensure you have roadrunner as a dependency in your
composer.json - Set
OCTANE_SERVER=roadrunnerusing the--build-argoption along with the build command
You can configure RoadRunner through
deployment/octane/.rr.prod.yaml.
// 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, ] ] ];Also, some useful Bash functions and aliases are added in utilities.sh that maybe help.
- Laravel Octane logs request information only in the
localenvironment. - Please be aware of
.dockerignorecontent
- Add support for Horizon
- Add support for RoadRunner
- 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
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.