Why do I need Docker for Laravel?

✔ Recommended Answer

You don't need Docker, it just (arguably) simplifies your development experience. Docker is a containerization solution where people create images that contain applications and packages which when deployed, provide an environment that meets their requirements. It's kind of similar to virtualization, only it works closer to the hardware so is more performant.

With Laravel the basic requirements are PHP, MySQL/MariaDB, and Apache/Nginx. There are other packages people frequently use alongside Laravel such as Redis, RabbitMQ & Memcache to name a few. Laravel Sail provides a wrapper around the Docker commands for starting and stopping containers (instances of Docker images) and some pre-configured environments. Sail currently provides images for PHP 7.4 and PHP 8 and Nginx and a choice of RDBMS and some other things like Redis.

By using Sail, you don't need to install and configure these things on your host system. You install Sail then run a few commands to install the packages you want and away you go.

Aside from simplifying the development experience, another nice added benefit is that you can create Docker environments for development and use the same image for production so you can be confident there will be no deployment issues (or at least shouldn't be!).

Again, you don't have to use Docker with Laravel. You are not missing out on anything by not using it, you just need to install and configure your environment manually on your host.

So in your scenario, if you were to not use Sail, you will need to install PHP, Nginx and either MySQL or MariaDB and Composer at a minimum. Take a look at this LEMP installation tutorial on how to go about and then watch the Laravel 8 from Scratch series (or at least the environment setup part) for things like Composer.

Method #2

Docker can be very useful when working with Laravel for a number of reasons.

Firstly, it allows you to create a consistent environment for your application across different machines and operating systems, which can be a major advantage when working with a team. By using Docker, you can ensure that everyone has the same dependencies and versions of software installed, reducing the risk of issues caused by differences in local environments.

Secondly, Docker allows you to easily manage and deploy your application in different environments. You can create Docker images of your application that include all the necessary dependencies and configuration, and then deploy those images to different servers or cloud platforms. This can simplify the deployment process and reduce the risk of issues caused by differences in the underlying environment.

Finally, Docker can also help you to isolate your application from other software running on your machine. This can be especially useful if you're working on multiple projects that require different versions of PHP or other dependencies. By using Docker containers, you can ensure that each project has its own isolated environment, without interfering with other projects or the underlying system.

Overall, while it's not strictly necessary to use Docker with Laravel, it can be a very useful tool for managing dependencies, deploying your application, and isolating your development environment.


Most Popular

Remove Unicode Zero Width Space PHP

PhpStorm, return value is expected to be 'A', 'object' returned

Laravel file upload returns forbidden 403, file permission is 700 not 755