Skip to content

Commit acf46fb

Browse files
rw4llldvdksn
authored andcommitted
guides: Add Docker+Laravel example
Signed-off-by: David Karlsson <[email protected]>
1 parent 4a6c5ae commit acf46fb

File tree

6 files changed

+881
-0
lines changed

6 files changed

+881
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Develop and Deploy Laravel applications with Docker Compose
3+
linkTitle: Laravel applications with Docker Compose
4+
summary: Learn how to efficiently set up Laravel development and production environments using Docker Compose.
5+
description: A guide on using Docker Compose to manage Laravel applications for development and production, covering container configurations and service management.
6+
tags: [frameworks]
7+
languages: [php]
8+
aliases:
9+
- /frameworks/laravel/
10+
params:
11+
time: 30 minutes
12+
resource_links:
13+
- title: Laravel
14+
url: https://laravel.com/
15+
- title: Docker Compose
16+
url: /compose/
17+
- title: Use Compose in production
18+
url: /compose/how-tos/production/
19+
- title: Repository with examples
20+
url: https://github.com/dockersamples/laravel-docker-examples
21+
---
22+
23+
Laravel is a popular PHP framework that allows developers to build web applications quickly and effectively. Docker Compose simplifies the management of development and production environments by defining essential services, like PHP, a web server, and a database, in a single YAML file. This guide provides a streamlined approach to setting up a robust Laravel environment using Docker Compose, focusing on simplicity and efficiency.
24+
25+
> **Acknowledgment**
26+
>
27+
> Docker would like to thank [Sergei Shitikov](https://github.com/rw4lll) for
28+
> his contribution to this guide.
29+
30+
The demonstrated examples can be found in [this GitHub repository](https://github.com/dockersamples/laravel-docker-examples). Docker Compose offers a straightforward approach to connecting multiple containers for Laravel, though similar setups can also be achieved using tools like Docker Swarm, Kubernetes, or individual Docker containers.
31+
32+
This guide is intended for educational purposes, helping developers adapt and optimize configurations for their specific use cases. Additionally, there are existing tools that support Laravel in containers:
33+
34+
- [Laravel Sail](https://laravel.com/docs/11.x/sail): An official package for easily starting Laravel in Docker.
35+
- [Laradock](https://github.com/laradock/laradock): A community project that helps run Laravel applications in Docker.
36+
37+
## What you’ll learn
38+
39+
- How to use Docker Compose to set up a Laravel development and production environment.
40+
- Defining services that make Laravel development easier, including PHP-FPM, Nginx, and database containers.
41+
- Best practices for managing Laravel environments using containerization.
42+
43+
## Who’s this for?
44+
45+
- Developers who work with Laravel and want to streamline environment management.
46+
- DevOps engineers seeking efficient ways to manage and deploy Laravel applications.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Common Questions on Using Laravel with Docker
3+
description: Find answers to common questions about setting up and managing Laravel environments with Docker Compose, including troubleshooting and best practices.
4+
weight: 40
5+
---
6+
7+
<!-- vale Docker.HeadingLength = NO -->
8+
9+
## 1. Why should I use Docker Compose for Laravel?
10+
11+
Docker Compose is a powerful tool for managing multi-container environments, particularly in development due to its simplicity. With Docker Compose, you can define and connect all necessary services for Laravel, such as PHP, Nginx, and databases, in a single configuration (`compose.*.yaml`). This setup ensures consistency across development, testing, and production environments, streamlining onboarding and reducing discrepancies between local and server setups.
12+
13+
While Docker Compose is a great choice for development, tools like **Docker Swarm** or **Kubernetes** offer advanced scaling and orchestration features, which may be beneficial for complex production deployments.
14+
15+
## 2. How do I debug my Laravel application with Docker Compose?
16+
17+
To debug your Laravel application in a Docker environment, use **Xdebug**. In the development setup, Xdebug is installed in the `php-fpm` container to enable debugging. Ensure Xdebug is enabled in your `compose.dev.yaml` file by setting the environment variable `XDEBUG_ENABLED=true` and configuring your IDE (e.g., Visual Studio Code or PHPStorm) to connect to the remote container for debugging.
18+
19+
## 3. Can I use Docker Compose with databases other than PostgreSQL?
20+
21+
Yes, Docker Compose supports various database services for Laravel. While PostgreSQL is used in the examples, you can easily substitute **MySQL**, **MariaDB**, or even **SQLite**. Update the `compose.*.yaml` file to specify the required Docker image and adjust your `.env` file to reflect the new database configuration.
22+
23+
## 4. How can I persist data in development and production?
24+
25+
In both development and production, Docker volumes are used to persist data. For instance, in the `compose.*.yaml` file, the `postgres-data-*` volume stores PostgreSQL data, ensuring that data is retained even if the container restarts. You can also define named volumes for other services where data persistence is essential.
26+
27+
## 5. What is the difference between development and production Docker configurations?
28+
29+
In a development environment, Docker configurations include tools that streamline coding and debugging, such as Xdebug for debugging, and volume mounts to enable real-time code updates without requiring image rebuilds.
30+
31+
In production, the configuration is optimized for performance, security, and efficiency. This setup uses multi-stage builds to keep the image lightweight and includes only essential tools, packages, and libraries.
32+
33+
It’s recommended to use `alpine`-based images in production for smaller image sizes, enhancing deployment speed and security.
34+
35+
Additionally, consider using [Docker Scout](/manuals/scout/_index.md) to detect and analyze vulnerabilities, especially in production environments.
36+
37+
For additional information about using Docker Compose in production, see [this guide](/compose/how-tos/production/).

0 commit comments

Comments
 (0)