Select Page

Laravel Octane with Swoole via Docker

February 8, 2023

Laravel Octane is still Laravel but on steroids. It claims that it can run your applications at supersonic speed. Sounds great! It’s docker time!

We have two choices on what server to use: Swoole or RoadRunner. I don’t want headaches so we will go with Swoole. It is only a PHP extension so it’s really easy to run it with PHP. For benchmarks, you can do your research yourself, but Swoole is in par with RoadRunner in terms of the number of requests it can handle.

Let’s proceed first on creating our base image that is running PHP with Swoole already installed.

I already created a Github repository for this and pushed it on to the Dockerhub. See the following links

Github, Dockerhub

And now let’s extend it for our Laravel usecase.

FROM jcfrane/php:8.2-swoole

RUN curl -sS | php — –install-dir=/usr/local/bin –filename=composer

RUN curl -fsSL | bash – && \
apt-get install -y nodejs \
build-essential && \
node –version && \
npm –version

RUN npm install –save-dev chokidar

COPY ./opt/php/php.ini /usr/local/etc/php/conf.d/php.ini
WORKDIR /var/www/html
COPY ./ .

RUN composer install –optimize-autoloader –no-dev

COPY /opt/php/ /usr/local/bin/
COPY /opt/php/ /usr/local/bin/
RUN chmod +x /usr/local/bin/
RUN chmod +x /usr/local/bin/
CMD [“php”, “artisan”, “octane:start”, “–host=”, “–watch”]



Submit a Comment

Your email address will not be published. Required fields are marked *