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:
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!
2
Answers
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
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.