A complete Docker development environment for Laravel applications with PHP 8.3, MySQL 8.0, Nginx, and Node.js 20.
- PHP 8.3 FPM - Latest PHP version with all required extensions
- MySQL 8.0 - Persistent database storage
- Nginx - High-performance web server
- Node.js 20 - For frontend asset compilation
- Vite - Lightning-fast frontend tooling
- Docker Volumes - Isolated vendor and node_modules management
- Hot Module Replacement - Live reload for frontend changes
- Docker Desktop installed
- Node.js installed locally (for running npm scripts)
- Git
-
Clone the repository
git clone https://github.com/YOUR_USERNAME/laravel-dockerized.git cd laravel-dockerized -
Run setup command
npm run docker:setup
This command will:
- Start all Docker containers
- Install Composer dependencies
- Install NPM dependencies
- Generate application key
- Run database migrations
-
Access the application
- Laravel App: http://localhost:8000
- Vite Dev Server: http://localhost:5173
- MySQL: localhost:3306
# Start containers
npm run docker:up
# Start Vite dev server (run in separate terminal)
npm run docker:dev
# Stop containers (database persists)
npm run docker:down# Restart containers
npm run docker:restart
# Fresh start (clean database)
npm run docker:fresh
# Access container bash
npm run docker:bash# Run artisan commands
npm run artisan migrate
npm run artisan make:controller UserController
npm run artisan cache:clear
npm run artisan route:list# Install package
npm run composer require package-name
# Update dependencies
npm run composer updatelaravel-dockerized/
βββ docker/
β βββ nginx/
β βββ default.conf # Nginx configuration
βββ Dockerfile # PHP container configuration
βββ docker-compose.yml # Docker services configuration
βββ package.json # NPM scripts
βββ README.md # This file
The .env file contains your application configuration:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel_dockerized
DB_USERNAME=laravel
DB_PASSWORD=Ensure your vite.config.js has the correct server settings:
export default defineConfig({
server: {
host: '0.0.0.0',
port: 5173,
strictPort: true,
hmr: {
host: 'localhost',
port: 5173,
},
},
});| Service | Container Name | Port | Description |
|---|---|---|---|
| app | laravel-dockerized-app | 5173 | PHP 8.3 FPM with Node.js |
| nginx | laravel-dockerized-nginx | 8000 | Nginx web server |
| mysql | laravel-dockerized-mysql | 3306 | MySQL 8.0 database |
vendor- Composer dependencies (isolated from local)node_modules- NPM packages (isolated from local)mysql_data- Database persistence
# Check what's using the port
netstat -ano | findstr :8000
# Stop containers and try again
npm run docker:down
npm run docker:up# Rebuild containers
docker-compose down -v
docker-compose build --no-cache
docker-compose up -d# Remove everything including volumes
docker-compose down -v
# Remove all unused Docker resources
docker system prune -a- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open-sourced software licensed under the MIT license.
Your Name - Mayur Shingrakhiya