Speeding up Docker for Mac

2020-12-08 20:50:58 +0100 +0100

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:

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

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=172.17.0.1 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.

Conclusion

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.