Docker on macOS Feels Slow: A Reality Check for Local Stacks
If you are running a local development stack like the one described in your configurationâcombining MySQL, Redis, Memcached, Nginx, and PHP-FPMâand experiencing sluggish performance or even timeouts on a new macOS machine with the latest Docker Desktop, the culprit is rarely the code itself. It is almost always the interaction between Apple's virtualization layer and the Docker daemon.
The specific symptoms you are facingâsymfony 4 projects taking minutes to build or respondâare characteristic of macOS when it attempts to utilize hardware acceleration features that may not be fully optimized or enabled by default on newer system versions. The core issue usually stems from how Docker Desktop manages the Linux kernel namespace and, critically, whether it is configured to use HyperKit or QEMU/KVM for virtualization.
The Virtualization Bottleneck
On macOS, Docker Desktop does not run natively; it runs inside a lightweight Linux VM (Docker Engine) that sits on top of your host OS. When you launch Docker, it attempts to start this engine. If the system settings are misaligned or if Apple's security updates have restricted access to certain virtualization extensions, the container runtime falls back to software emulation.
This fallback results in significant overhead. Instead of leveraging the CPU's hardware instructions for virtualization (Intel VT-x or AMD-V), Docker is forced to emulate them via software. This increases context switching latency and memory usage, which directly translates to the "very slow" feel when compiling Symfony assets or querying your universal-mariadb2 container.
Checking Your System Configuration
Before attempting complex kernel modifications, verify that you are not running in a mode that disables hardware acceleration. Open Docker Desktop and navigate to Preferences > General. Ensure that the option "Use the Hypervisor framework" is enabled if your macOS version supports it (typically macOS 12 Monterey and later). If this is unchecked, Docker relies on HyperKit, which can be slower depending on the specific Apple silicon or Intel chip architecture.
However, there is a more direct solution often overlooked: the Virtualization option within the Docker preferences. In many recent updates to Docker Desktop on macOS, there is a setting to "Use QEMU" under the General tab. By default, Docker might try to use HyperKit, which has known performance regressions on certain macOS versions due to how it handles networking and disk I/O with large file systems.
Switching to QEMU forces Docker to use a more robust, though sometimes heavier, virtualization backend that handles volume mounting (like your ../data/db:/var/lib/mysql volumes) much more efficiently. This change alone frequently resolves the "it is not even working" timeouts associated with database connections in your stack.
Optimizing Volume Mounts
Your docker-compose.yml exposes several named and bind-mounted volumes:
.:/application(bind mount for code)../data/db:/var/lib/mysql(persistent data)./phpdocker/nginx/nginx.conf(configuration)
Bind mounts on macOS are notoriously slow because the host file system (APFS or HFS+) and the container's Linux file system must translate paths at every read/write operation. When you run composer install or Symfony's asset compiler, thousands of small files are being created in /application. On a standard bind mount, this I/O bottleneck is severe.
If you cannot migrate to a fully native Linux setup immediately (such as using Boot Camp or a WSL2-like environment), consider moving your heavy-write directories to a Docker-managed volume instead. For example, change:
volumes:
- .:/application
to:
volumes:
- source-app:/app
And then define source-app in the volumes section as an anonymous or named volume. While this adds a slight layer of indirection, it often bypasses the APFS-to-ext4 translation overhead for the specific paths that are being written to most frequently, like vendor directories or compiled assets.
The Modern Alternative: Docker Compose V2
Finally, ensure you are using Docker Compose V2 syntax and commands. The version "3.1" in your YAML is compatible, but the CLI tools have evolved. Running docker compose up --build -d can sometimes hang if the build cache is corrupted from a previous slow run. Clearing the build cache before restarting your stack helps:
docker system prune -a
This command removes unused containers and images, which can free up memory resources that were being held by zombie processes from the initial slow startup sequence.
When to Move On
If switching to QEMU and optimizing volumes does not yield acceptable performance, you may need to consider that Docker on macOS is simply not designed for heavy compilation tasks. The overhead of running a Linux kernel inside a VM on top of macOS is real. For production-grade local development where every second counts, using a native Linux environment (via Virtualization.app with a full Ubuntu/Debian distro) or a dual-boot setup eliminates the virtualization layer entirely. Until then, tweaking the Docker Desktop settings to prioritize QEMU over HyperKit is the most immediate technical fix for your universal-mariadb2 and symfony slowdowns.
