This project provides a collection of Docker containers designed to streamline local development setups for Laravel
applications.
It includes containers for running a PHP environment, PostgreSQL database, an SMTP server for email
testing, and a Nginx web server.
Each container is configured using Dockerfiles and a docker-compose.yml
file,
enabling developers to quickly spin up an environment tailored for modern web development.
The main purpose of this project is to:
- Simplify the process of setting up a development environment using Docker.
- Provides a unified ecosystem for building and testing Laravel applications.
- Include additional tools like Xdebug for debugging, Mailpit for email testing, and PostgreSQL as a database backend.
This setup is ideal for developers who want a pre-configured, containerized development environment.
-
php84.Dockerfile
:- Builds a PHP 8.4 environment with FPM.
- Includes support for PostgreSQL (
pdo_pgsql
), GD for image manipulation, Composer, and Node.js. - Configures Xdebug for PHP debugging.
-
postgres17.Dockerfile
:- Builds a PostgreSQL 17 database container.
- Relies on environment variables from
.env
for database credentials.
-
mailpit12.Dockerfile
:- Create an SMTP testing server using Mailpit.
- Useful for capturing and testing outgoing emails in development environments.
-
nginx12.Dockerfile
:- Configures a Nginx web server using the provided template
vhost.exemple.conf
file. - Supports PHP applications and restricts access to sensitive files.
- Configures a Nginx web server using the provided template
-
vhost.exemple.conf
:- Template file to define the Nginx virtual host configuration.
- Supports PHP routing and implements basic security rules.
- Developers should copy this to
web/vhost.conf
and adjust the values as needed.
-
.env.example
:- Template file for defining environment variables.
- Developers should copy this to
.env
and adjust the values as needed.
-
docker-compose.yml
:- Orchestrates all containers and defines their configurations, networking, volume mappings, and exposed ports.
Follow these steps to set up and run the project on your local machine.
Ensure the following is installed on your system:
Clone the repository from your version control system.
git clone <repository-url>
cd <repository-folder>
Create a copy of the .env.example
file and rename it to .env
.
cp .env.example .env
Edit the .env
file to set environment variables as needed.
Create a copy of the web/vhost.exemple.conf
file and rename it to web/vhost.conf
.
cp web/vhost.exemple.conf web/vhost.conf
Edit the web/vhost.conf
file to set the Nginx working directory.
To do this, rename NGINX_WORKING_DIR
variable in the root directive.
You can adjust another config as needed.
Use the following command to build and run the Docker containers:
docker-compose build
build
: Ensures all Docker containers are rebuilt using the latest configurations.
docker-compose up -d
up
: Runs the containers.-d
: Runs the containers in detached mode (in the background).
To verify the running containers, execute:
docker ps
You should see the following containers running:
- PHP (Container name:
php84
) - Nginx (Container name:
nginx12
) - PostgreSQL (Container name:
postgres17
) - Mailpit (Container name:
mailpit12
)
-
PHP (php84):
- Vite Server Port:
5173
(adjustable indocker-compose.yml
)
- Vite Server Port:
-
Nginx (nginx12):
- Port:
8084
(adjustable indocker-compose.yml
)
- Port:
-
PostgreSQL (postgres17):
- Port:
5432
(adjustable indocker-compose.yml
)
- Port:
-
Mailpit (mailpit12):
- Web Interface:
http://localhost:8025
- SMTP Port:
1025
- Web Interface:
Visit http://localhost:8084
in your browser to check the Nginx server.
Mailpit’s interface is accessible at http://localhost:8025
. You can use SMTP testing on port 1025
.
Connect to the PostgreSQL container using your preferred database client or via the command line:
docker exec -u <POSTGRES_USER> -it postgres17 bash
Use the credentials set in the .env
file.
-
Debugging with Xdebug:
- Xdebug is pre-installed and configured in the PHP container for remote debugging.
- Ensure your IDE (like PhpStorm) is configured to work with Xdebug. Use the
xdebug.ini
file for reference.
-
Volume Mappings:
- Shared volumes ensure changes to your files on the host machine are reflected inside the containers.
-
Data Persistence:
- PostgreSQL and Mailpit use persistent storage to preserve data across container restarts (
postgresql17-data
andmailpit12-data
volumes).
- PostgreSQL and Mailpit use persistent storage to preserve data across container restarts (
To stop the containers, run:
docker-compose down
To start the containers, run:
docker-compose up -d
To remove containers, use:
docker-compose down --volumes