Speeding up Docker for Mac

tl;dr: don’t even try

I recently attempted to use Docker for Mac with my local MediaWiki setup (using MediaWiki’s docker-compose.yml). As is well-known Docker for Mac struggles with a large number of files synchronized across the host and container file system. In my case, I had ~400,000 files as I had run composer install / npm install in multiple extension directories, along with MediaWiki core.

After a bunch of fruitless battles to deal with the file synchronization issue (exploring mutagen, old file system vs new filesystem, excluding directories from sync, reducing number of files involved in directory sync, :cached vs :delegated flags, etc) I decided to explore an idea I’ve had in mind for a while now, which is to use a remote server as my local dev environment. (If this seems like a step backwards in local development progress, well yeah it probably is, but I’m exploring it for now.)

What I’ll need:

  • A remote server. I have an account on DigitalOcean so I created a 4GB RAM box in Frankfurt, near my location in Germany. I added a firewall via the DigitalOcean UI to block all traffic except for SSH, which is also locked to only allow access via keys.
  • An SSH tunnel to route network traffic from the server to my laptop. I need port 8080 for accessing the Apache service on the MediaWiki container and I also want port 9009 which I use for XDebug.
  • A way to sync files realtime-ish between the server and my laptop. I’m attempting to use syncthing per this post.
  • Ability to execute docker and docker-compose – I can do this directly on the server or I can do export DOCKER_HOST=ssh://user@host docker run ... in locally on my laptop.

The SSH tunnel command I landed on is: ssh -L 8080:{serverIp}:8080 -R {serverIp}:9009:localhost:9009 {serverUser}@{serverIp}.

Then, on the server I can use docker-compose up -d in my mediawiki/core directory (making sure I’ve set a docker-compose.override.yml file as instructed by MediaWiki’s DEVELOPERS.md so that file permissions are correct), and on my laptop I can access the site at http://localhost:8080.


XDebug was a bit trickier to sort out. You need to edit your /etc/ssh/sshd_config file on the server to set GatewayPorts on, and restart the SSH service on the server.

Then, what is also important is to make sure that your XDEBUG_CONFIG in the .env file has the correct remote_host value. What I ended up with is XDEBUG_CONFIG=remote_enable=1 remote_host= remote_port=9009. Note that the IP was retrieved via the instructions from DEVELOPERS.md, which tells you to run ip -4 addr show docker0 on the host.

Side note: XDebug has a really cool command-line debugging client for troubleshooting connections, dbgpClient. I used this on the server to check that I was receiving connections from the container. Then I ran it locally on my laptop to verify I was receiving connections from the remote server. The flow is: XDebug in the container sends traffic on port 9009 to the host IP (the remote DigitalOcean server) and then that traffic is routed via ssh -R to my laptop, where PhpStorm handles the request.


Too early to draw conclusions as I just set this up a few days ago, but I’ll write another post if I end up abandoning or modifying the general setup.