Rails assets are very slow on MacOX Docker

Viewed 2625

I have noticed that assets requests are very, very slow on my Rails app. When volumes are inside docker image it takes around 20 ms to get asset file. When I am starting container and mount files, it takes around 400 ms to fetch them!

Docker filesystem is slow, but rails app boot time is pretty much same in both cases, so its not necessary the reason. Do you have an idea what could be reason here?

1 Answers

I had the same issue and was like impossible work in development environment with a Dockerized Rails application because on Mac is terrifically slow.

This is a known issue, Docker is very slow on Mac and Windows, in particular due to Volumes mounting.

First of all we took some precautions:

  1. Be sure that you are not mounting big files or folders. For example my log directory size was 10GB! You can install ncdu to find big files/folders, follow this: https://maketips.net/tip/461/docker-build-is-slow-or-docker-compose-build-is-slow
  2. Check if you are facing this network known issue: https://github.com/docker/compose/issues/3419#issuecomment-221793401

Anyway above precautions didn't helped too much.

The big improvement was adding docker-sync gem! Check-out this: http://docker-sync.io/

Basically with this gem you are using a different approach to sync folders between your machine and app container. This works very well and now everything is very fast, almost similar to Linux performance!

Related