

This is how the project directory should look. Once you’ve cloned the code base, open it using Visual Studio Code or whatever code editor you like and take a good look at the directory structure. Feel free to clone mine from this repository. To follow along, you’ll need a Laravel application. I’ve made a fork of the repository, ported it from Debian to Alpine, and made necessary modifications as per my needs. Bret Fisher has created the php-docker-good-defaults repository quite some time ago. Instead, I’ll show you how I make my own base image. In this article, I’ll not use any pre-built base Laravel docker image. This is an excellent image with tons of customization options and easy-to-follow documentation. One such image that I often use, is the webdevops/php-nginx image. There are a number of pre-built base images out there that come with both PHP-FPM and NGINX.

Even if you manage to install NGINX on a PHP image, it can be tricky to keep both NGINX and PHP-FPM running. Nothing’s wrong with that, but that image doesn’t come with NGINX pre-installed. When it comes to containerizing a PHP or Laravel application, it’s common practice to use the official php image as a base. If you know a more optimized way of doing this, please share in the comments and take everything I say with a grain of salt. This is just one of them that I’ve used in past. One more disclaimer before I begin: Things like containerizing or deploying an application can be done in several ways. In this article, I’ll walk you through the process of containerizing a Laravel application for both the development and the production environment.įor your convenience, I’ve uploaded my code to this repository, feel free to fork and modify it. Although spinning up separate containers for php-fpm and NGINX is not that much of a hassle in development, in a production environment, the best way is to combine PHP-FPM and NGINX in a single image and develop as close to production as possible. When you’re packaging a Laravel or PHP application in general, it’s not just the application.ĭepending on what your application is doing, it’ll depend on PHP-FPM, composer, a bunch of packages and NGINX, at the very least. But not in the case of a Laravel application.

In most cases, putting an application inside an OCI image and distributing it through one of the popular image registries is pretty easy. Due to its flexibility and ease of usage, Docker has become one of the most widely used, if not the most widely used, methods of distributing software.
