Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel + Docker guide #21276

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0ae8bd3
Add initial laravel example pages
rw4lll Oct 29, 2024
9098194
Added external link support for resource links in the sidebar
rw4lll Oct 29, 2024
2d069c6
fixes and improvements
rw4lll Oct 29, 2024
71a1eb2
fixes and improvements
rw4lll Oct 29, 2024
a5a7c1f
Update content/guides/frameworks/laravel/development-setup.md
rw4lll Oct 30, 2024
a9870a2
Update content/guides/frameworks/laravel/production-setup.md
rw4lll Oct 30, 2024
57f7655
Update content/guides/frameworks/laravel/development-setup.md
rw4lll Oct 30, 2024
dd9102e
Update content/guides/frameworks/laravel/production-setup.md
rw4lll Oct 30, 2024
d2713be
Update content/guides/frameworks/laravel/production-setup.md
rw4lll Oct 30, 2024
c13166e
Merge branch 'main' into laravel-compose
rw4lll Oct 30, 2024
5f5c0c3
added tag support
rw4lll Oct 31, 2024
09f3333
Update content/guides/frameworks/laravel/development-setup.md
rw4lll Nov 4, 2024
06a6a70
Update content/guides/frameworks/laravel/_index.md
rw4lll Nov 4, 2024
ac5281c
Update content/guides/frameworks/laravel/_index.md
rw4lll Nov 4, 2024
665fc3a
Update content/guides/frameworks/laravel/prerequisites.md
rw4lll Nov 4, 2024
b2e3e8c
Update content/guides/frameworks/laravel/prerequisites.md
rw4lll Nov 4, 2024
10b1359
Update content/guides/frameworks/laravel/prerequisites.md
rw4lll Nov 4, 2024
85aba4d
Update content/guides/frameworks/laravel/prerequisites.md
rw4lll Nov 4, 2024
b151dce
Update content/guides/frameworks/laravel/prerequisites.md
rw4lll Nov 4, 2024
97cf0f1
Update content/guides/frameworks/laravel/production-setup.md
rw4lll Nov 4, 2024
eaac035
Apply suggestions from code review
rw4lll Nov 4, 2024
ed71738
remove compose-lp-survey-anchor tag, adjust newlines
rw4lll Nov 4, 2024
8e48d11
remove external link property
rw4lll Nov 4, 2024
eec526c
Update content/guides/frameworks/laravel/prerequisites.md
rw4lll Nov 4, 2024
06acc91
Merge branch 'docker:main' into laravel-compose
rw4lll Dec 26, 2024
a0b8b25
fix updates for dev setup
rw4lll Dec 26, 2024
87dd807
Merge branch 'main' into laravel-compose
rw4lll Dec 26, 2024
0775159
Merge branch 'laravel-compose' of github.com:rw4lll/docker-docs into …
rw4lll Dec 26, 2024
1c491a6
Update the production setup page
rw4lll Dec 26, 2024
77b1aad
update the guide following the example update and code review+
rw4lll Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions content/guides/frameworks/laravel/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Develop and Deploy Laravel applications with Docker Compose
linkTitle: Laravel applications with Docker Compose
summary: Learn how to efficiently set up Laravel development and production environments using Docker Compose.
description: A guide on using Docker Compose to manage Laravel applications for development and production, covering container configurations and service management.
tags: [frameworks]
languages: [php]
aliases:
- /frameworks/laravel/
params:
time: 30 minutes
resource_links:
- title: Laravel
url: https://laravel.com/
- title: Docker Compose
url: /compose/
- title: Use Compose in production
url: /compose/how-tos/production/
- title: Repository with examples
url: https://github.com/rw4lll/laravel-docker-examples
---

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.

The demonstrated examples can be found in [this GitHub repository](https://github.com/rw4lll/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.

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:

- [Laravel Sail](https://laravel.com/docs/11.x/sail): An official package for easily starting Laravel in Docker.
- [Laradock](https://github.com/laradock/laradock): A community project that helps run Laravel applications in Docker.

## What you’ll learn

- How to use Docker Compose to set up a Laravel development and production environment.
- Defining services that make Laravel development easier, including PHP-FPM, Nginx, and database containers.
- Best practices for managing Laravel environments using containerization.

## Who’s this for?

- Developers who work with Laravel and want to streamline environment management.
- DevOps engineers seeking efficient ways to manage and deploy Laravel applications.
37 changes: 37 additions & 0 deletions content/guides/frameworks/laravel/common-questions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Common Questions on Using Laravel with Docker
description: Find answers to common questions about setting up and managing Laravel environments with Docker Compose, including troubleshooting and best practices.
weight: 40
---

## Common Questions

### 1. Why should I use Docker Compose for Laravel?

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.

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.

### 2. How do I debug my Laravel application with Docker Compose?

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.

### 3. Can I use Docker Compose with databases other than PostgreSQL?

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.

### 4. How can I persist data in development and production?

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.

### 5. What is the difference between development and production Docker configurations?

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.

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.

It’s recommended to use `alpine`-based images in production for smaller image sizes, enhancing deployment speed and security.

Additionally, consider using **Docker Scout** to scan for vulnerabilities, especially in production environments. For more information, refer to the [Docker Scout documentation](/scout/).

For additional information about using Docker Compose in production, see [this guide](/compose/how-tos/production/).
Loading