A pretty configurable and production ready multi-stage Dockerfile for Laravel Octane powered web services and microservices.
The Docker configuration provides the following setup:
- Debian Buster 10
- PHP 8.0 with preconfigured JIT compiler and OPcache
- Swoole extension with support of:
- OpenSSL
- HTTP/2
- Native cURL hook for coroutines
mysqlnd
- Asynchronous DNS
And the following PHP extensions are included:
- Swoole
- OPcache
- Redis
- PCNTL
- BCMath
- RDKAFKA
- INTL
- pdo_mysql
- MySQL Client
- zip
- cURL
- GD
- mbstring
Exposed ports of container:
Software | Port |
---|---|
Swoole | 9000 |
-
Clone this repository:
git clone [email protected]:viethc/laravel-octane-docker.git
-
Copy cloned directory content including
deployment
directory,Dockerfile
and.dockerignore
into your Octane powered Laravel project -
Change directory to your Laravel project
-
Build your image:
docker build -t <container-name>:<tag> .
-
Up the container:
docker run -p <port>:9000 --rm <container-name>:<tag>
-
Visit
http://localhost:<port>
You can use this Dockerfile within Laravel Sail. Just change PHP container context
to .
and add <port>:9000
to ports
in docker-compose.yml
. You maybe need to remove WWWGROUP
in args
and WWWUSER
in environment
configuration in this file.
There are something that you maybe want to configure:
- Application request workers count in
supervisord.conf
- Max request count for request workers in
supervisord.conf
- The amount of workers available to process concurrent tasks in
supervisord.conf
- OPcache and JIT configurations in
opcache.ini
- PHP configurations in
php.ini
ENTRYPOINT
Bash script inentrypoint.sh
- Set OS timezone using the
--build-arg
option along with the build command
// config/octane.php
return [
'swoole' => [
'options' => [
'user' => 'octane',
'group' => 'octane',
'http_compression' => true,
'http_compression_level' => 6, // 1 - 9
'compression_min_length' => 20,
'open_http2_protocol' => true,
'open_cpu_affinity' => true,
'tcp_fastopen' => true,
'open_tcp_keepalive' => true,
'open_tcp_nodelay' => true,
'enable_reuse_port' => true,
]
]
];
Also, some useful Bash functions and aliases are added in utilities.sh
that maybe help.
- Laravel Octane logs requests information only in the
local
environment.
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.