skip to Main Content

How can I recreate this?

Create install from Laravel 8 docs and Laravel Sail docs.

I use the sail up command, which works great. The command builds docker containers, connects them, and makes development as easy as we can imagine, especially for VSCode, and this works fine, but it’s slow in development with WSL2. I mean commands like `sail npm run dev.’ Any ideas on how to speed this up?

FYI: The same project that runs on the same machine is at least 10x faster. For more information, I ran tests on i9-10900X, 32 GB RAM on Docker Desktop for Windows 10.

docker-compose.yml

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
    mysql:
        image: 'mysql:8.0'
        ports:
            - '${DB_PORT}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
        volumes:
            - 'sailmysql:/var/lib/mysql'
        networks:
            - sail
    redis:
        image: 'redis:alpine'
        ports:
            - '${REDIS_PORT}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - 1025:1025
            - 8025:8025
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sailmysql:
        driver: local
    sailredis:
        driver: local

2

Answers


  1. You should run docker from WSL2 if possible.

    1. Install docker and WSL2.
    2. Move your project to WSL by opening \wsl$ in explorer and navigating to your VM’s home, in my case \wsl$Ubuntu-20.04homethomas

    enter image description here

    1. Run docker-compose up -d / sail up from the VM

    enter image description here

    Login or Signup to reply.
  2. I was going to explain this but just go here and read for yourself. This is what helped me. VSCode kinda yelled at me when I opened up a project in the default location and gave me this link. https://learn.microsoft.com/en-us/windows/wsl/compare-versions

    Performance across OS file systems

    We recommend against working across operating systems with your files,
    unless you have a specific reason for doing so. For the fastest
    performance speed, store your files in the WSL file system if you are
    working in a Linux command line (Ubuntu, OpenSUSE, etc). If you’re
    working in a Windows command line (PowerShell, Command Prompt), store
    your files in the Windows file system.

    For example, when storing your WSL project files:

    • Use the Linux file system root directory: \wsl$Ubuntu-18.04home<user name>Project
    • Not the Windows file system root directory: C:Users<user name>Project

    All currently running distributions (wsl -l) are accessible via
    network connection. To get there run a command [WIN+R] (keyboard
    shortcut) or type in File Explorer address bar \wsl$ to find
    respective distribution names and access their root file systems.

    You can also use windows commands inside WSL’s Linux Terminal. Try
    opening a Linux distribution (ie Ubuntu), be sure that you are in the
    Linux home directory by entering this command: cd ~. Then open your
    Linux file system in File Explorer by entering (don’t forget the
    period at the end): powershell.exe /c start .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search