I tried to run a fresh Laravel 9.2 project with Laravel Sail in Docker. (contains WSL2), and the index page is loaded in 2sec. For an existing project where I tried Sail to run on Docker, it takes ~7sec instead of 0.3 as it takes on Laravel Homestead.
I find a similar post here: , but is still not working.
- I have tried Ubuntu, Ubuntu 20.04 is the same. On Ubuntu 18 I don’t have
in /mnt/c disk not sure why. - I have tried to run on wsl 1, and disable Use the WSL 2 based engine from Docker, and to enable Expose daemon on tcp://localhost:2375 without TLS, but then when I try to run
./vendor/bin/sail up
is not working anymore "Docker is not running", from what I checked on Laravel page , I need WSL2.
docker-compose.yml (generated by Laravel Sail)
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'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local
2
Answers
Its because of the section
Its a bind mount to windows filesystem.
Don’t put it on a windows filesystem tho as it will slow down things a lot.
Put your docker-compose.yml file inside the WSL2 for example
\wsl$Debianhome[username]projects[your_project]
And then compose it up from there, it will be much faster.
This is a common WSL2 rule, if u use host bind mount
volumes
section for any service – store your source code in the WSL 2 filesystem not on windows fs. Its not needed for docker managed volumes.You dont need to change anything else, nor should, leave wsl2 engine enabled and use only wsl2.
Where are your project files located?
If you installed your laravel project with composer and they are on your c drive or other local disk this could be the problem.
Put the project files in your linux home directory
e.g.wsl$Ubuntuhome[username][your project]