15

I have quite a bit of experience developing Rails 4 apps on Mac OS X + Docker Machine + Docker Compose, but something has changed with how Rails 5 is caching files in the development environment (currently testing with RC1).

After starting the application with docker-compose up, the application runs normally in development mode.

But if I make a change to a controller or model, the only way I can get that reflected in the application is to stop the server and start it back up.

So now my workflow looks something like this when I need to make a change to a controller or model:

  1. Make change to controller/model class.
  2. Stop server with Ctrl + C.
  3. Start server back up with docker-compose up.
  4. Wait on the server to start up.
  5. Run whatever I was running in the browser.

To say the least, needing to do steps 2-4 is annoying and not what I'm accustomed to from Rails 4.

I went a step further and uninstalled Spring using the Removal instructions, but I still get the same behavior.

I also searched for any settings that I could find in config/environments/development.rb related to the Rails runtime's iron grip on the model and controller classes, and I couldn't find anything. (I assume that it really wants to rely on watching the filesystem in order to selectively load changes, and something isn't being picked up from a change on Mac to VirtualBox.)

Any other ideas on what I can try? Or are there any new settings related to how this more aggressive caching works?

Chris Peters
  • 17,918
  • 6
  • 49
  • 65
  • Any news on this? Even with config.file_watcher = ActiveSupport::FileUpdateChecker nothing for me. Rails doesn't update code until I don't restart with docker-compose up. How to fix, also with workaround? –  Aug 21 '16 at 17:50
  • Great question. I'm having exactly same issue, Rails5, docker-compose and OSX Sierra. No controllers/locales changes, but views erb for some reason are being updated. Last week at an Rails4 app didn't have the issue. – unmultimedio Nov 15 '16 at 17:35

1 Answers1

16

I'm Using Rails 5 rc1.

Rails 5 introduced some "improvements" to code reloading, but it doesn’t seem to work with Docker on OS X.

So in config/environments/development.rb, I replaced

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

with

config.file_watcher = ActiveSupport::FileUpdateChecker

It seems that for the ActiveSupport::EventedFileUpdateChecker file watcher, the change event does not occur for docker-machine shared files

Soviut
  • 88,194
  • 49
  • 192
  • 260
mdkrog
  • 378
  • 2
  • 13
  • Are you using the beta of Docker for Mac or your own Docker Machine install using VirtualBox? I seem to be having fewer issues with this after disabling Spring with the new Docker for Mac, which has way better volume mounting from the host to the guest VM. – Chris Peters Jul 07 '16 at 12:21
  • This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/12929922) – Jonathan Argentiero Jul 07 '16 at 13:56
  • @michalmuskala I don't agree with what either of you are saying. – Chris Peters Jul 07 '16 at 18:54
  • @JonathanArgentiero I don't agree with what either of you are saying. – Chris Peters Jul 07 '16 at 18:54
  • My comment is to clarify that I've moved on from the VirtualBox-based install to a new one since asking this question in May, so this may be a non-issue in that scenario. I intend to try his suggestion though to see if it helps get Spring working again. – Chris Peters Jul 07 '16 at 18:54
  • @ChrisPeters have you maybe solved this problem? I've the same issue on Rails 4.2.7 when using docker native for OSX, spring is not a problem here, I've tried with and without it and the problem persists :/ – mswiszcz Nov 07 '16 at 13:30
  • @mswiszcz Sorry, I am running Rails 4.2.7 and 5.0.0 apps just fine on Docker for OSX. If your problem relates to 4.2.7, you may want to ask another question here on Stack Overflow with some details like your `Dockerfile` (and `docker-compose.yml` if you're using Compose). – Chris Peters Nov 11 '16 at 16:53
  • Made the change and it worked for me. OSX Sierra, Rails 5, and Docker Stable for Mac. Had the same issue, only views were being updated, now seems to be controllers/locales are being updated as it should. – unmultimedio Nov 15 '16 at 17:42
  • I had the same issue running Docker in Windows 10. This answer fixed the issue for me. Thx! – Chiefwarpaint Jan 16 '18 at 20:10
  • this is sufficient for rails 5.1.5 on docker 18.02 + parallels on mac using docker-machine 0.13.0 – JPowell Mar 28 '18 at 20:43