You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+66-59
Original file line number
Diff line number
Diff line change
@@ -21,87 +21,114 @@
21
21
22
22
## Overview
23
23
24
-
The **Laravel Docker Examples Project**provides practical examples and comprehensive guidance for Laravel developers to create modern, efficient, and flexible Docker environments for both development and production. By demonstrating best practices and offering detailed configurations, this project helps you build Docker images tailored for Laravel applications. Whether you're new to Docker or looking to optimize your deployment workflow, these examples serve as a solid foundation to understand and extend Docker functionalities in your Laravel projects.
24
+
The **Laravel Docker Examples Project**offers practical and modular examples for Laravel developers to create efficientDocker environments for development and production. This project demonstrates modern Docker best practices, including multi-stage builds, modular configurations, and environment-specific customization. It is designed to be educational, flexible, and extendable, providing a solid foundation for Dockerizing Laravel applications.
25
25
26
26
27
27
## Project Structure
28
28
29
-
The project is organized into the following main directories:
29
+
The project is organized as a typical Laravel application, with the addition of a `docker` directory containing the Docker configurations and scripts. These are separated by environments and services. There are two main Docker Compose projects in the root directory:
30
30
31
-
-**example-app**: Contains a sample Laravel 11 application used to test and demonstrate Docker environments.
32
-
-**development**: Includes Docker configurations and Compose files for setting up a complete development environment.
33
-
-**production**: Contains Dockerfiles and Compose files optimized for a production environment.
31
+
-**compose.dev.yaml**: Orchestrates the development environment.
32
+
-**compose.prod.yaml**: Orchestrates the production environment.
34
33
35
-
### example-app
34
+
### Directory Structure
36
35
37
-
The `example-app` directory holds the sample Laravel application. It includes basic routes, a health check endpoint to test database and Redis connections, and demonstrates how to integrate Laravel with Docker. This serves as a practical example to illustrate the concepts discussed in this project.
├── compose.dev.yaml # Docker Compose for development
45
+
├── compose.prod.yaml # Docker Compose for production
46
+
└── .env.example # Example environment configuration
47
+
```
40
48
41
-
Located in the `development` directory, this environment focuses on providing a flexible and independent setup that includes all necessary tools for typical Laravel development:
49
+
This modular structure ensures shared logic between environments while allowing environment-specific customizations.
42
50
43
-
-**Services**: PHP-FPM, Nginx, Node.js, Redis, and PostgreSQL.
44
-
-**Hot Reloading**: Supports live reloading of code changes without rebuilding containers.
45
-
-**Custom Dockerfiles**: Allows customization of images to include extensions and tools needed for development.
46
-
-**Docker Compose**: Orchestrates the various services, making it easy to start and stop the entire environment.
47
51
48
52
### Production Environment
49
53
50
-
The `production` directory emphasizes building a slim, secure, and efficient Docker image suitable for deploying a Laravel application in production:
54
+
The production environment is configured using the `compose.prod.yaml` file. It is optimized for performance and security, using multi-stage builds and runtime-only dependencies. It uses a shared PHP-FPM multi-stage build with the target `production`.
51
55
52
-
-**Optimized Images**: Uses multi-stage builds to keep the final image size small.
53
-
-**Pre-Built Assets**: Assets are compiled during the build process to ensure the container is ready to serve content immediately.
-**Pre-Built Assets**: Assets are compiled during the build process, ensuring the container is ready to serve content immediately upon deployment.
58
+
-**Health Checks**: Built-in health checks monitor service statuses and ensure smooth operation.
54
59
-**Security Best Practices**: Minimizes the attack surface by excluding unnecessary packages and users.
55
-
-**Docker Compose for Production**: Provides a Compose file tailored for deploying the application with services like Nginx, PHP-FPM, Redis, and PostgreSQL.
60
+
-**Docker Compose for Production**: Tailored for deploying Laravel applications with Nginx, PHP-FPM, Redis, and PostgreSQL.
61
+
62
+
This environment is designed for easy deployment to any Docker-compatible hosting platform.
63
+
64
+
65
+
### Development Environment
66
+
67
+
The development environment is configured using the `compose.dev.yaml` file and is built on top of the production version. This ensures the development environment is as close to production as possible while still supporting tools like Xdebug and writable permissions.
68
+
69
+
Key features include:
70
+
-**Close Parity with Production**: Mirrors the production environment to minimize deployment issues.
71
+
-**Development Tools**: Includes Xdebug for debugging and writable permissions for mounted volumes.
72
+
-**Hot Reloading**: Volume mounts enable real-time updates to the codebase without rebuilding containers.
73
+
-**Services**: PHP-FPM, Nginx, Redis, PostgreSQL, and Node.js (via NVM).
74
+
-**Custom Dockerfiles**: Extends shared configurations to include development-specific tools.
75
+
76
+
To set up the development environment, follow the steps in the **Getting Started** section.
56
77
57
78
58
79
## Getting Started
59
80
60
81
Follow these steps to set up and run the Laravel Docker Examples Project:
61
82
62
-
### Clone the Repository
83
+
### Prerequisites
84
+
Ensure you have Docker and Docker Compose installed. You can verify by running:
If these commands do not return the versions, install Docker and Docker Compose using the official documentation: [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/).
70
92
71
-
1. Navigate to the specific example in Development Directory:
2. Copy the .env.example file to .env and adjust any necessary environment variables:
100
+
### Setting Up the Development Environment
101
+
102
+
1. Copy the .env.example file to .env and adjust any necessary environment variables:
78
103
79
104
```bash
80
105
cp .env.example .env
81
106
```
82
107
83
-
3. Start the Docker Compose Services:
108
+
Hint: adjust the `UID` and `GID` variables in the `.env` file to match your user ID and group ID. You can find these by running `id -u` and `id -g` in the terminal.
0 commit comments