Reputation: 313
TL;DR 2: Years later, still writing Symfony projects (now on Symfony 7.2) I use Mutagen to sync up the project folder with the local disk, with the support for a blazingly fast 980 EVO Pro 2 SSD backing it up. Avarage times dropped from 2-3 seconds per request to mere 10ths of milleseconds (generally 70ms for a new install).
TL;DR 1: 14 months after I read about WSL2 coming for Windows (and Docker) I tried Symfony 5 and it is still slow as chocolate balls.
Back in Q1 2020 I read about Symfony and Docker being very slow in an easy set-up environment. We tried and tried, but to no avail: we couldn't get Symfony sub 4.000ms no matter how hard we tried. One of the solutions obviously was moving the vendor folder outside the bind-mount managed by Docker and Window (which is accessible through explorer.exe) and the same goes for the var directory (for logs and cache).
It now being Q2 2021, well over a year later, I rotate between PHP and .NET but still I wanted to give it a try. I downloaded the freshest version of Docker Desktop for Windows I could find, together with Hyper-V and WSL2 support. I installed the support drivers from Microsoft and I was set to begin.
A small hour later, after looking up some data on how Docker actually worked again, I quickly deployed a PHP 7.4, NGINX, PostgreSQL, MongoDB and Redis container/stack and it all worked fluently with a simple phpinfo() and some random calls to the aforementioned databases.
I installed a brand new Symfony 5 and to my surprise I still found that the problem persisted. No connection to the database has even been made and still it failed to function. Naturally I simplified my stack back to a PHP 7.4 and NGINX stack, hoping somewhere I eagerly lost my way. Unfortunately I was met by a rude awakening - it still sucks chocolate balls.
My setup
# ./docker-compose.yml
version: '3'
services:
php-fpm:
build:
context: ./php-fpm
volumes:
- ../src:/var/www
networks:
- symfony
nginx:
build:
context: ./nginx
volumes:
- ../src:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/sites/:/etc/nginx/sites-available
- ./nginx/conf.d/:/etc/nginx/conf.d
- ./logs:/var/log
depends_on:
- php-fpm
ports:
- "80:80"
networks:
- symfony
networks:
symfony:
PHP-FPM
# ./php-fpm/Dockerfile
FROM php:7-fpm-alpine
RUN apk --update --no-cache add git nano
COPY --from=composer /usr/bin/composer /usr/bin/composer
WORKDIR /var/www
CMD php-fpm
EXPOSE 9000
NGINX
FROM nginx:alpine
WORKDIR /var/www
CMD ["nginx"]
EXPOSE 80
As you can ascertain from my example above I have a src
folder which plain and simply holds a symfony new src --full
install with all the bells and whistles provided by the basic installation - nothing more.
The only solution I could find to make my installation fly was to do the following inside the php-fpm
container:
cd /var/www
rm -rf var/
mv vendor ..
ln -s /vendor vendor/
mkdir /var-symfony
chmod 777 /var-symfony
ln -s /var-symfony var/
While I can simply put this in a Dockerfile or the compose YAML it begs the question: why the flippin' freck is this slow as fluid doo-doo? I thought they might've fixed it after at least a year of tons of complaints.
I also found the networks
option which is reflected in my YAML. That didn't solve anything either. Maybe it'll lower the TCP connection due to it being TCP and not directly onto a socket but I have yet to try and bench that.
I read up on some stuff creating a volume using docker, which somewhat solves the problem but not entirely. It still feels like patchwork for something that should work out-of-the-box.
Does anyone have a real world usecase where this actually works?
Upvotes: 9
Views: 5846
Reputation: 3344
If your bind mount is pointing to a folder on a Windows partition you will most likely get horrible performance. What I do is I clone the repo inside WSL in ~/dev
(where I put all my projects), then I run my containers from WSL's shell (I use Ubuntu 20.04). Then to be able to use my IDE (PhpStorm) and get the code in sync, I open the project from the \\wsl$\Ubuntu-20.04\home\julien\dev\my-prohect\
. If you are using VS Code, there is an extension for that https://code.visualstudio.com/blogs/2019/09/03/wsl2.
I did create a mapped drive to make all of this even easier. In Windows' CMD:
net use U: \\wsl$\Ubuntu-20.04 /PERSISTENT:YES
Upvotes: 15