Spinning a full VM up and down can take a while. Both my router and MacBook Pro to factory settings and seen no speed increases.Working at a consultancy, sometimes I need to switch back and forth between multiple projects in a day. Docker Desktop is an application for MacOS and Windows machines for the building and sharing of containerized applications and microservices.Here is a summary of the tweaks to optimise Mac clients for Synology SMB. File access from host mounted volumes is slow, CPU performance takes a significant hit. Docker on mac is, and always will be, slow. Hypothetically, it offers all the benefits of virtualized development environments like Vagrant (stable, re-creatable, isolated, etc.) but requires fewer resources.Docker is native on linux, run via virtualisation elsewhere.This may be due to running asset pipelines like those of Rails or Ember that generate tons of temporary files.Most sharing systems ( VirtualBox, NFS) do not support ignoring subdirectories. Generally speaking, sharing files between MacOS and a virtual OS on a hypervisor breaks down when too many reads or writes are required in a short amount of time. Specifically, I am thinking of the speed of shared volumes. Sharing is Caring (About File IO Speed)I suspected—correctly—that Docker would fall prey to some of the same shortcomings as Vagrant. Then I went to DockerCon this April, which finally gave me enough momentum to figure out how to integrate it into my development workflow.
![]() Docker Too Slow Plus Vim OrEditing the code in the container via SSH plus Vim or EmacsEach of the solutions mentioned above has drawbacks: Using rsync or similar utilities that have to run separately but allow for ignoring subdirectories Using SSHFS to share files out of the container/guest back to the host Doing the reads/writes on the host and pushing the finished output into the container/guest What’s a Developer to Do?Generally, this problem leads you to one of the following solutions: I’m looking at you, Ember. Additionally, having the code “live” in something as ephemeral as a Docker container seems like a bad idea. Searching the shared files from the host can be slow, to say nothing of editor tooling with compiled languages like TypeScript or C#. SSHFS: Personally, I’ve found this very flaky, especially if your computer goes to sleep. ![]() This gem even takes file sharing a step farther, using Docker volumes in conjunction with rsync/unison for optimum performance.For instance, in my Rails project’s Dockerfile, I ADD just enough files to run bundle install, then I mount in my source directory via docker-compose. Rsync and unison allow you to exclude subdirectories, so you can ignore. Docker-sync and Upcoming ChangesDocker-sync is a very handy Ruby gem that makes it easy to use rsync or unison file sharing with Docker. But if you want to stay in MacOS and use Docker, I have a few tips to make your life better. File sharing between the Docker machine and containers is extremely fast. You could develop in a windowed Linux environment (native or virtual) that functions as the Docker machine. Running the script brought performance back to approximately the same as native. I noticed this when our Rails database migrations took around 10 times longer to run on Docker for Mac versus native.After a bit of searching, I found this script on a GitHub issue. Slow IO±It’s More than Just Volume MountingAnother disk IO problem you might run into using Docker for Mac is slow database speed. The improvements for reading speed are coming soon, but last I checked, the improvements for writing speed (the more common problem in my experience) are still a ways out. Also, if you are using rsync, you’ll need to docker cp the automatically updated Gemfile.lock back out of the container to the host.Docker is working on some improvements to Docker for Mac that may significantly improve the speed of reads and writes–provided you are okay with eventual consistency. So, for example, if you add a gem to your Gemfile and bundle install, you’ll eventually need to rebuild your base image.Generally, you should just run docker-compose up -build to make sure your image doesn’t get too out of date. Learn french software for macThe container revolution is just getting started.If you’re at all on the fence, I encourage you to try out Docker. The Moby project will help developers pick and choose what parts of the tools they want to use.I have faith that in a year or two, the file sharing/disk IO speed problems will be a distant memory. So is the whole Docker ecosystem.Multi-stage builds are going to streamline the process of creating development and production images. I Still Want to Docker All the ThingsDeveloping in Docker isn’t perfect, but the workflow is improving rapidly. Consequently, I like docker-sync in that getting back to “vanilla” Docker for Mac is as simple as tweaking the volumes in docker-compose.yml and dropping docker-sync.yml. So I’m betting on Docker for Mac long-term. My assumption is that Docker will prioritize Docker For Mac as the preferred/default way to develop on a Mac, versus using a standalone VM as your docker machine. It’s possible the second option you presented would fix this, though, since the files “live” on the docker machine / VirtualBox VM.That said, one of my other goals was to (semi)-seamlessly transition back to standard Docker for Mac volumes, if and when they fix their speed issues. Those seem like good options for many use cases.If I recall correctly, nfs sharing had decent performance for the Rails pipeline but choked on Ember’s build pipeline.
0 Comments
Leave a Reply. |
Details
AuthorJoseph ArchivesCategories |