Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

A Symfony or PHP app in Docker Desktop for Mac takes seconds per request

Your error

Symfony pages take several seconds in Docker Desktop on a Mac but respond quickly on a Linux server1 more line it can show

Fix it fast

Most common cause, 1 of 3

vendor/ and var/ sit on the bind mount

Lay named volumes over vendor and var so those paths stay inside the VM, then fill vendor once from inside the container.

Fix
services:
  php:
    volumes:
      - ./:/var/www/app
      - vendor:/var/www/app/vendor
      - var:/var/www/app/var
volumes:
  vendor:
  var:

docker compose up -d
docker compose exec php composer install
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Docker Desktop on macOS runs containers in a Linux VM, so each file a request reads from a bind mount crosses a host-to-VM share. Symfony reads thousands of files from vendor/ and keeps cache and logs in var/. Put vendor/ and var/ in named volumes, use VirtioFS for file sharing, and try synchronized file shares for very large projects.

  • Applies to Docker Desktop 4.x on macOS, Docker Compose v2 and newer, Symfony 7 and 8.1, PHP 8.3 to 8.5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Time one console command inside the container, then list what compose.yaml bind-mounts from the Mac. A project mount with no volume over vendor or var points to the first cause.

Run this first
time docker compose exec php php bin/console cache:clear
docker compose config | grep -n -B1 -A4 "type: bind"

Then find the line you see in this list and open its fix:

  1. 1vendor/ and var/ sit on the bind mountcompose.yaml mounts the whole project, for example ./:/var/www/app, and no named volume covers vendor or var
  2. 2File sharing still runs on gRPC FUSESettings > General in Docker Desktop shows gRPC FUSE as the file sharing implementation
  3. 3The project is too big for a virtual file shareVirtioFS is on and vendor lives in a volume, yet file-heavy commands stay slow in a repository with a very large file count

What does the error look like?

  • Symfony pages take several seconds in Docker Desktop on a Mac but respond quickly on a Linux server
  • composer install and bin/console cache:clear are much slower inside the container than on the host

Cause 1 of 3

vendor/ and var/ sit on the bind mount

You seecompose.yaml mounts the whole project, for example ./:/var/www/app, and no named volume covers vendor or var

Check

Docker's settings guide for Mac says file sharing adds overhead because host changes must be reported to the Linux VM, and that cache directories or databases perform much better when kept inside the VM. A Symfony project mounted whole breaks that advice: Composer's vendor tree and the var/cache and var/log folders all travel through the share.

Check
docker compose config | grep -n -A3 'target: /var/www/app'

Fix

Lay named volumes over vendor and var so those paths stay inside the VM, then fill vendor once from inside the container. The host copy of vendor then stops changing, so run composer install on the Mac as well if your IDE needs it.

Fix
services:
  php:
    volumes:
      - ./:/var/www/app
      - vendor:/var/www/app/vendor
      - var:/var/www/app/var
volumes:
  vendor:
  var:

docker compose up -d
docker compose exec php composer install

Verify

The same timed command finishes far sooner than before.

Verify
time docker compose exec php php bin/console cache:clear

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

File sharing still runs on gRPC FUSE

You seeSettings > General in Docker Desktop shows gRPC FUSE as the file sharing implementation

Check

Docker Desktop for Mac can share host files through VirtioFS or gRPC FUSE. VirtioFS is the default and the one Docker recommends for speedy file sharing, so a setting switched during earlier troubleshooting leaves every bind mount on the slower path.

Check
# Docker Desktop > Settings > General > Choose file sharing implementation

Fix

Select VirtioFS, apply, and let Docker Desktop restart the VM; containers come back with the new file share.

Fix
# Docker Desktop > Settings > General
#   file sharing implementation: VirtioFS
#   Apply & restart
docker compose up -d

Verify

The setting shows VirtioFS after the restart, and the timed command improves.

Verify
time docker compose exec php php bin/console about

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

The project is too big for a virtual file share

You seeVirtioFS is on and vendor lives in a volume, yet file-heavy commands stay slow in a repository with a very large file count

Check

Docker aims synchronized file shares at codebases of 100,000 files or more, where VirtioFS and gRPC FUSE no longer scale. Docker Desktop then keeps a synchronized copy of the host folder in the VM, and bind mounts of that folder read from the copy.

Check
find . -type f | wc -l

Fix

The feature needs you signed in to Docker Desktop. Under Settings > Resources > File sharing, choose Create share in the Synchronized file shares block and pick the project folder. Each share holds about 2 million files at most, so split larger trees into several shares.

Fix
# Docker Desktop > Settings > Resources > File sharing
#   Synchronized file shares > Create share > select the project folder
# wait for: Watching for filesystem changes

Verify

The share's status reads Watching for filesystem changes, and the timed command speeds up without any change to compose.yaml.

Verify
time docker compose exec php php bin/console cache:clear

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Start every PHP compose.yaml with named volumes for vendor, var, node_modules and database data, and bind-mount only the source code.
  • Keep Settings > Resources > File sharing limited to the folders your containers need, as Docker's guide recommends.
  • Run composer install inside the container after each change to composer.lock, because the volume copy of vendor does not follow the host folder.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Dispatch Pro, Spotless Laundry.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.