Skip to main content
Submitted by lwinmaungmaung on
Dockerizing Laravel

Dockerizing Laravel is still way difficult for me until I found this thing. When I am doing a study on NestJS with 100 days commitment (Click here to watch on Youtube). At the section of deployment, nodeJS is already a headache. It means I am a Laravel developer. Then, deploying is also some sort of headache for me, unless you use Laravel Forge or some tools. However, in NestJS, there is a method that containerize the NestJS Application to the docker and push it immediately.

It sparks me a solution. How can I do it for Laravel?

Dockerizing Laravel - Requirements

Dockerizing Laravel is not very difficult. It supports both traditional PHP-FPM method and Laravel Octane Method. The former is using Nginx+PHP+FPM+Script but the latter using some libraries to serve the app or expose directly on the public network without necessary use of any External Server.

I found the Dockerfile but sadly, I have some limitation on finding how to build and run the docker command. Then I refer from NestJS Documentation and a bit tweaking, Voila, IT WORKS.

The docker file is the same as documentation, and let me slow down the code.

  1. Install laravel octane - composer require laravel/octane
  2. Install core and frankenphp - php artisan octane:install and choose frankenPHP.
  3. create Dockerfile in your project root folder.
  4. docker build -t $your-app-name . (include dot)
  5. docker run -p 8000:8000 $your-app-name

Then you will get your laravel application dockerized.

Happy Dockerization.