0

I have an api which we update to laravel 8 to be able to use laravel sail, I mean to have it in docker, but when using the api endpoints, when it is up in docker, they take an average of 30 seconds each endpoint, I attach one image:

enter image description here

I also attach the configuration of my docker-compose:

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./docker/7.4
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-7.4/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
            - redis
            - meilisearch
            - selenium
    mysql:
        image: 'mysql:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3307}: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
        command:
           - --sort_buffer_size=1073741824
        healthcheck:
          test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
          retries: 3
          timeout: 5s
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "redis-cli", "ping"]
          retries: 3
          timeout: 5s
    meilisearch:
        image: 'getmeili/meilisearch:latest'
        ports:
            - '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
        volumes:
            - 'sailmeilisearch:/data.ms'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "wget", "--no-verbose", "--spider",  "http://localhost:7700/health"]
          retries: 3
          timeout: 5s
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - '${FORWARD_MAILHOG_PORT:-1025}:1025'
            - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
    selenium:
       image: 'selenium/standalone-chrome'
       volumes:
            - '/dev/shm:/dev/shm'
       networks:
           - sail
networks:
    sail:
        driver: bridge
volumes:
    sailmysql:
        driver: local
    sailredis:
        driver: local
    sailmeilisearch:
        driver: local

The system used is windows to lift the laravel sail.

It should be noted that when I use the api without lifting the docker, the average time it takes is less than 5 seconds. Also check if docker had some kind of limitation in terms of CPU and RAM but it figures that it has assigned about 12GB and 4 cores to use. If anyone has any idea where the problem could come from, it would help me a lot.

Greetings and thanks!

Tprogramer
  • 85
  • 1
  • 14
  • 1
    Are you using WSL? This may help if not https://stackoverflow.com/questions/65227492/laravel-8-laravel-sail-for-dev-on-windows-10-is-slow-how-to-speed-up – rbaskam Nov 25 '21 at 13:58
  • @rbaskam Yes, I am using the WSL to get the docker up – Tprogramer Nov 25 '21 at 14:05
  • 1
    https://laracasts.com/discuss/channels/general-discussion/laravel-sail-docker-is-slow?reply=702984 Does this help in any way? – rbaskam Nov 25 '21 at 14:08

2 Answers2

0

That's odd as mine is working fine with no delays. Btw, this is my copy of docker-composer.yml, try checking it out. Though the only difference is that I'm using PHP 8 instead of PHP 7.4 but that shouldn't be an issue.

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./docker/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
            - selenium
     mysql:
         image: 'mysql:8.0'
         ports:
             - '${FORWARD_DB_PORT:-3306}: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
         healthcheck:
           test: ["CMD", "mysqladmin", "ping"]

    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "redis-cli", "ping"]
    meilisearch:
        image: 'getmeili/meilisearch:latest'
        ports:
            - '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
        volumes:
            - 'sailmeilisearch:/data.ms'
        networks:
            - sail
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - '${FORWARD_MAILHOG_PORT:-1025}:1025'
            - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
    selenium:
       image: 'selenium/standalone-chrome'
       volumes:
            - '/dev/shm:/dev/shm'
       networks:
           - sail
networks:
    sail:
        driver: bridge
volumes:
    sailmysql:
         driver: local
    sailredis:
        driver: local
    sailmeilisearch:
        driver: local
jrran90
  • 668
  • 12
  • 18
  • Sure, using a different version of php I don't think that is the problem, something that I did not mention in the post is that I am using Windows on my machine, do you also use Windows? – Tprogramer Nov 25 '21 at 13:49
  • I actually use mac and windows 10 for development purposes and I can attest that both are working fine. Try checking your window for updates, coz that contains some fixes too and use the latest release of docker – jrran90 Nov 25 '21 at 13:58
  • How strange, I'll keep looking to see what I find, thank you anyway – Tprogramer Nov 25 '21 at 14:06
  • don't know if this will make an impact or effect but have you tried my `docker-compose.yml`? since I've noticed as well that there are variables like this `XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'` Just in case. :) – jrran90 Nov 25 '21 at 14:09
  • 1
    I'm going to pop it to see what happens, use version 8 and also that of xdebug. Thank you for your contribution, I will be letting you know what happens – Tprogramer Nov 25 '21 at 14:19
  • Try with your docker-compose and it still takes forever to run without the docker – Tprogramer Nov 25 '21 at 17:31
0

Finally I was able to solve it by putting the project inside the folders of the ubuntu virtual machine, this makes docker to read the files much faster.

The information I got from these posts:

Laravel 8 & Laravel Sail for dev on Windows 10 is slow. How to speed up?

Laravel Sail / Docker is slow

Tprogramer
  • 85
  • 1
  • 14