5

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
Beusebiu
  • 1,433
  • 4
  • 23
  • 68

2 Answers2

1

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$\Ubuntu\home[username][your project]

leighboz
  • 119
  • 7
0

Its because of the section

 volumes:
   - '.:/var/www/html'

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$\Debian\home\[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.

Programista
  • 1,037
  • 5
  • 15
  • 38
  • I tried to change the volume, but when I run ./vendor/ bin/sail up, I get 'Could not open input file: /var/www/html/artisan' – Beusebiu Apr 07 '22 at 07:19
  • Im sorry i cannot help u with Laravel Sail, maybe ask their support or discord, but it is docker and this is why it is super slow, u need to put the docker-compose.yml inside the WSL2 filesystem and run it from there. Also this is the recommended setup from laravel itself https://laravel.com/docs/9.x/installation#getting-started-on-windows so i dont know why it isn't working for you. – Programista Apr 08 '22 at 15:11