Laravel with Sail and Docker, really slow
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# Laravel Sail with Docker: Why Performance Disparity Happens and How to Fix It
As a senior developer working with modern PHP frameworks like Laravel, we often lean into containerization solutions like Docker and tools like Laravel Sail to ensure environment consistency across development, staging, and production. However, when performance bottlenecks appear—especially when comparing local VM setups (like Homestead) against Docker environments—it can be frustrating.
I’ve encountered a common issue: running Laravel applications via Sail in Docker seems significantly slower than traditional virtual machine setups. This post dives deep into why this performance discrepancy occurs and provides actionable steps to optimize your Dockerized Laravel experience, ensuring you get fast, reliable development cycles.
## The Performance Gap: Homestead vs. Docker Overhead
The difference in speed you are observing between running Laravel on Homestead (which relies on a full virtual machine) and using Laravel Sail within Docker often boils down to the overhead of the virtualization layer versus containerization.
Homestead provides a complete operating system environment, which is powerful but resource-intensive. Docker containers, while incredibly lightweight compared to VMs, still introduce overhead related to the operating system kernel layers, network stack management, and volume I/O when dealing with file operations typical in application development.
When you move from Homestead's environment directly to a containerized setup, especially on Windows hosts utilizing WSL2, we need to ensure that the underlying communication between the host OS (Windows) and the Linux containers is optimized for maximum throughput. The performance bottleneck is rarely the Laravel code itself; it’s usually in the I/O operations and network latency introduced by the virtualization layer interaction.
## Mastering the WSL2 and Docker Interaction
Your experience highlights a critical point: the health of your Docker setup is intrinsically linked to how you manage the underlying Linux environment on Windows. As noted in many community discussions, leveraging **WSL2 (Windows Subsystem for Linux)** is non-negotiable for optimal Docker performance.
If you are still relying on older WSL1 or misconfigured settings, the communication latency between the host machine and the Docker daemon becomes a major performance drag. The flags you mentioned regarding `Expose daemon on tcp://localhost:2375 without TLS` are often related to enabling non-standard networking required for seamless interaction between Windows services and Linux containers, but only when the foundation (WSL2) is correct will these settings yield tangible speed improvements.
### Optimizing Your `docker-compose.yml`
The structure of your `docker-compose.yml` generated by Sail is generally sound, correctly defining interdependent services like the application container and the MySQL database. However, performance can be subtly improved by optimizing how persistent data is handled:
```yaml
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html' # Volume mounting is key for fast file access
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql/mysql-server:8.0'
# ... (rest of the MySQL configuration remains standard)
```
Notice the volume mount (`.:/var/www/html`). Ensure that your host machine’s file system (managed by WSL2) can access these volumes efficiently. Slow disk I/O is often the real culprit when working with large application codebases in containers.
## Conclusion: The Path to High-Performance Laravel Development
The slow performance you experienced is usually an environmental issue stemming from subsystem configuration rather than a flaw in Laravel or Sail itself. To achieve high-speed development with Docker and Laravel, focus on these three pillars:
1. **Mandate WSL2:** Ensure your entire development environment runs on the WSL2 engine. This provides the necessary kernel and I/O performance required for efficient container interaction.
2. **Verify Networking:** Confirm that resource exposure and networking settings are configured to allow fast communication between the host and the Docker daemon without unnecessary TLS overhead if possible.
3. **Monitor I/O:** Pay attention to disk read/write speeds when running Artisan commands or accessing application files within the container.
By ensuring a robust foundation with WSL2, you unlock the containerization potential of Laravel Sail, allowing you to enjoy the speed and consistency that modern DevOps practices promise. For more context on structuring scalable applications, always refer back to the official guidelines provided by [laravelcompany.com](https://laravelcompany.com).