Skip to content

Commit 883364a

Browse files
committed
update README
1 parent 039f32c commit 883364a

File tree

1 file changed

+66
-59
lines changed

1 file changed

+66
-59
lines changed

README.md

+66-59
Original file line numberDiff line numberDiff line change
@@ -21,87 +21,114 @@
2121

2222
## Overview
2323

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 efficient Docker 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.
2525

2626

2727
## Project Structure
2828

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:
3030

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.
3433

35-
### example-app
34+
### Directory Structure
3635

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.
38-
39-
### Development Environment
36+
```
37+
project-root/
38+
├── app/ # Laravel app folder
39+
├── ... # Other Laravel files and directories
40+
├── docker/
41+
│ ├── common/ # Shared configurations
42+
│ ├── development/ # Development-specific configurations
43+
│ ├── production/ # Production-specific configurations
44+
├── compose.dev.yaml # Docker Compose for development
45+
├── compose.prod.yaml # Docker Compose for production
46+
└── .env.example # Example environment configuration
47+
```
4048

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.
4250

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.
4751

4852
### Production Environment
4953

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`.
5155

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.
56+
- **Optimized Images**: Multi-stage builds ensure minimal image size and enhanced security.
57+
- **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.
5459
- **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.
5677

5778

5879
## Getting Started
5980

6081
Follow these steps to set up and run the Laravel Docker Examples Project:
6182

62-
### Clone the Repository
83+
### Prerequisites
84+
Ensure you have Docker and Docker Compose installed. You can verify by running:
6385

6486
```bash
65-
git clone https://github.com/rw4lll/laravel-docker-examples.git
66-
cd laravel-docker-examples
87+
docker --version
88+
docker compose version
6789
```
6890

69-
### Setting Up the Development Environment
91+
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/).
7092

71-
1. Navigate to the specific example in Development Directory:
93+
### Clone the Repository
7294

7395
```bash
74-
cd development/nginx-fpm
96+
git clone https://github.com/rw4lll/laravel-docker-examples.git
97+
cd laravel-docker-examples
7598
```
7699

77-
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:
78103

79104
```bash
80105
cp .env.example .env
81106
```
82107

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.
109+
110+
2. Start the Docker Compose Services:
84111

85112
```bash
86-
docker compose up -d
113+
docker compose -f compose.dev.yaml up -d
87114
```
88115

89-
4. Install Laravel Dependencies:
116+
3. Install Laravel Dependencies:
90117

91118
```bash
92-
docker compose exec workspace bash
119+
docker compose -f compose.dev.yaml exec workspace bash
93120
composer install
94121
npm install
95122
npm run dev
96123
```
97124

98-
5. Run Migrations:
125+
4. Run Migrations:
99126

100127
```bash
101-
docker compose exec workspace php artisan migrate
128+
docker compose -f compose.dev.yaml exec workspace php artisan migrate
102129
```
103130

104-
6. Access the Application:
131+
5. Access the Application:
105132

106133
Open your browser and navigate to [http://localhost](http://localhost).
107134

@@ -111,40 +138,40 @@ Here are some common commands and tips for using the development environment:
111138

112139
### Accessing the Workspace Container
113140

114-
The workspace container includes Composer, Node.js, NPM, and other tools necessary for development.
141+
The workspace sidecar container includes Composer, Node.js, NPM, and other tools necessary for Laravel development (e.g. assets building).
115142

116143
```bash
117-
docker compose exec workspace bash
144+
docker compose -f compose.dev.yaml exec workspace bash
118145
```
119146

120147
### Run Artisan Commands:
121148

122149
```bash
123-
docker compose exec workspace php artisan migrate
150+
docker compose -f compose.dev.yaml exec workspace php artisan migrate
124151
```
125152

126153
### Rebuild Containers:
127154

128155
```bash
129-
docker compose up -d --build
156+
docker compose -f compose.dev.yaml up -d --build
130157
```
131158

132159
### Stop Containers:
133160

134161
```bash
135-
docker compose down
162+
docker compose -f compose.dev.yaml down
136163
```
137164

138165
### View Logs:
139166

140167
```bash
141-
docker compose logs -f
168+
docker compose -f compose.dev.yaml logs -f
142169
```
143170

144171
For specific services, you can use:
145172

146173
```bash
147-
docker compose logs -f web
174+
docker compose -f compose.dev.yaml logs -f web
148175
```
149176

150177
## Production Environment
@@ -158,26 +185,6 @@ The production environment is designed with security and efficiency in mind:
158185
- **HTTPS Setup**: While not included in this example, it's recommended to configure SSL certificates and use HTTPS in a production environment.
159186

160187

161-
### Building and Running the Production Environment
162-
163-
1. **Navigate to the specific example in Production Directory :**
164-
165-
```bash
166-
cd production/nginx-fpm/
167-
```
168-
169-
2. Copy the .env.example file to .env (compose env, not the laravel env file) and adjust any necessary environment variables:
170-
171-
```bash
172-
cp .env.example .env
173-
```
174-
175-
3. Start the Docker Compose Services:
176-
177-
```bash
178-
docker compose up -d
179-
```
180-
181188
### Deploying
182189

183190
The production image can be deployed to any Docker-compatible hosting environment, such as AWS ECS, Kubernetes, or a traditional VPS.

0 commit comments

Comments
 (0)