How I deploy Laravel apps in Docker with just two commands

WBOY
Release: 2024-09-08 06:33:06
Original
831 people have browsed it

Hi there! It's Jorge. It's been a while since my last post, and this one might sound the same as one that you might have read around here. But come along and I promise you that you never again will have to build docker images from scratch to your Laravel projects!

⚡TL;DR

Tired of configuring Docker from scratch for every Laravel project? This is the link to the Github repository for the Laradocker project, a brand new composer package that sets up your Laravel project with Docker with just these two simple commands:

# Run these commands inside your Laravel project:

composer require --dev jdsantos/laradocker

php artisan laradocker:install

# That's it! Follow the instructions and you are done!

Copy after login

On your way there, please leave a star ⭐ on the repo to show your support.

Thanks in advance ❤️

?The backstory

In my previous post, I brought you LANPOD a Laravel/Docker deployment strategy that allows you to deliver a Laravel app on-premise or cloud environments relying on a battle tested tech recipe consisting of laravel + alpine linux + nginx + php-fpm + opcache + docker you absolutely loved.

This recipe allows you to deploy your app in a redistributable, virtualized, os agnostic, self-contained and self-configured software image and run it in virtualization engines such as Docker or Podman. It even includes things out of the box like the supervisor's tidy configuration for handling your queues, nice defaults for php, opcache and php-fpm, nginx, etc.

All good, but...

?The pain

Something was off.

While LANPOD as a template repository on Github was a helpful starting point for a brand new Laravel app, and a LOT better than having to go about wiring virtualization over and over again on the same structured apps, it was completely useless to an already existing/legacy project. You would have to MANUALLY extract the recipe’s files and directories of the bunch of other stuff, and adapt them to your needs. As it was meant to be a template-only repository, it didn’t include right out of the box any native database support (because if it did, it would have to include all of them in the same image), and if an update to the configuration was needed, it would be hell on earth just to know how and what to change in your project.

?The solution

Having felt this pain myself enough times already, especially when having to add by hand the database dependencies to the Dockerfile/Containerfile over and over again, I realized: how cool would it be to have this recipe as a dependency in my projects, in such a way that is easy peasy to install, uninstall and update in the future?

"That's it! I'm going to create a Laravel package that I can install in my projects! Let's do this!"

How I deploy Laravel apps in Docker with just two commands

So, the adventure began!

I started to scaffold my brand new composer project with all required dependencies to develop and test Laravel packages including orchestra/testbench, laravel/pint and larastan/larastan.

After that, I set up right from the start a Github repository for the project, auto-publish capabilities to Packagist, the PHP composer package repository, and spawned Github actions for a super simple CI/CD pipeline to run my tests at each push.

With all this in place, the rest was peanuts: I used all of LANPOD's files as mere stubs for this project, and used the plain Artisan Console to develop a pretty silly and basic UI for installing this recipe:

How I deploy Laravel apps in Docker with just two commands

After launching Laradocker inside your project, the installer will guide you through the necessary steps to build the proper dependencies in the image, such as database connectivity support and you are done!

How I deploy Laravel apps in Docker with just two commands

All files get generated in an instant and copied into your project!

?‍?The code

This package is completely free & open-source and you can find the source code here!. On your way there, please leave a star ⭐ on the repo to show your support.

Thanks in advance ❤️

? Environment

This was the environment that I used:

Hardware

  • Intel i7-8750H
  • 24 GB of RAM
  • SSD 250GB

Software

  • Windows 11 Enterprise
  • Docker Desktop with WSL backend
  • Visual Studio Code

Hope this helped you in any way.

See you soon! ?

The above is the detailed content of How I deploy Laravel apps in Docker with just two commands. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template