DEV Community

Discussion on: Speed up Laravel in Docker by moving vendor directory

Collapse
 
cavo789 profile image
Christophe Avonture

Hello. Can you explain why putting the vendor folder one level up (not under /srv/app) make laravel faster ?

In my crurent set-up I'm putting the vendor folder as a subfolder (normal situation) but don't synchronize it on my machine.

My docker-compose file is creating a volume for the vendor folder so only in the container.

When I code, I'm using vscode and develop inside the container so I've well m'y vendor (auto-complete is working and I can debug too).

This said I'm really interested to hear more about your settings and how the performances are better.

Thanks

Collapse
 
tylerlwsmith profile image
Tyler Smith

Moving the vendor folder into another directory that resides in the container itself is faster than accessing mounted volumes on Docker Desktop in Windows/MacOS because it doesn't have to cross between the host OS and Docker Desktop's Linux VM. The container is able to access files that only exist in the container much quicker than it can access files that are mounted from the host OS.

As far as my other performance optimizations in the Dockerfile, I enabled PHP OpCache. Kristoffer Högberg has a concise write-up on how to do this.

Collapse
 
cavo789 profile image
Christophe Avonture

Oh? I think I've said the same... (I was on my smartphone, probably not the best to write a comment).

I'm putting my ~/vendor folder only in the container; not on my host (in my case, Windows). I'm running docker-composer myapp composer update in my container and I've created an internal volume to map the vendor folder so stay in the container and is not synchronized on my host.

My question was: why put you the folder not in the application directory but somewhere (so you've forced to update the ~/public/index.php file). Using an internal volume achieve the same result without the need to hack some Laravel file like index.php.

For OpCache, yes, I've just played right now with it and the improvement is really nice (github.com/cavo789/docker_php_opcache), about 30% faster.

Thread Thread
 
tylerlwsmith profile image
Tyler Smith

Can you give me an example of what you have in mind? I don't think I understand what you're trying to do.