rails: Code is not reloaded in dev with Docker on OS X

Steps to reproduce

  1. Install the Docker toolbox on OS X. Here are my instructions to install it with brew.
  2. Clone https://github.com/jeromedalbert/rails_5_rc1_docker. I have created this dummy application specifically for this issue.
  3. Follow the short instructions to set up the project and have a server running.
  4. Open the application in your browser.
  5. While the server is running, edit app/controllers/static_controller.rb and change 'hello world!' to 'coconut'.
  6. Reload the page in your browser.

Expected behavior

The page should display “coconut”.

Actual behavior

The page displays the old “hello world!” text.

System configuration

Rails version: 5.0.0.rc1

Ruby version: 2.3.1

Workaround

To make code reloading work for now, in config/environments/development.rb replace

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

with

config.file_watcher = ActiveSupport::FileUpdateChecker

Restart everything, and code reloading should work.

Additional comments

I have a feeling that for the ActiveSupport::EventedFileUpdateChecker file watcher, the change event does not occur for docker-machine shared files. So it may be more about docker-machine than Rails. But since I am not versed enough in the EventedFileUpdateChecker internals, I cannot say for sure.

Even if it is docker-machine’s fault, since I cannot pinpoint the exact problem, I would not know how to articulate it if I were to open an issue on their github repo. We might also find a workaround in Rails or add a warning the Rails documentation. That’s why I am opening this issue here. Any insight would be appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 22
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Just to add to this issue. If you are running your Rails app within a VirtualBox VM, then you are highly likely to experience this too. It doesn’t always happen though so it’s very tricky to diagnose properly.

Updates made to views won’t reflect until you full restart the Rails server.

To fix the issue:

In environments/development.rb, comment out: config.file_watcher = ActiveSupport::EventedFileUpdateChecker

Add: config.file_watcher = ActiveSupport::FileUpdateChecker

Current version of what I’m running (for context):

  • Rails 6.0.0
  • Vagrant 2.2.4
  • VirtualBox 6.0

@mrkongo Go to config/environments/development.rb and comment

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

out. If not needed for anything else, you may also want to remove the listen gem dependency in Gemfile.

For me the EventedFileUpdateChecker does not work even on bare macOS without Docker. Switching to FileUpdateChecker solved the issue.

Opened an issue w/ Docker as well https://github.com/docker/for-mac/issues/4962.

Here’s a repo for reproduction w/ instructions: https://github.com/jenfi-eng/docker-rails-reload-issue

It’s probably just my system, but I recently upgraded to Docker Desktop Community 2.4.0.0 for Mac and lost file updates in Docker.

It works fine if I’m running on my host machine (OSX) or if I switch the file_watcher to FileUpdateChecker.

[EDIT] So, maybe not my system, I downgraded Docker Desktop from 2.4.0.0 => 2.3.0.5 and it started working again using EventedFileUpdateChecker.

FileUpdateChecker fix doesn’t work properly on:

  • docker-machine version 0.11.0, build 5b27455
  • Docker version 17.05.0-ce, build 89658be

After change, code is reloaded with ~5 min lag, which makes code reload feature practically useless. Is there any workaround for this?

Thank you.

The docker on OSX runs on a thin Linux virtual machine. The virtual machine provisioners share code between the VM and the host on a file system that doesn’t support notification events, so we cannot use the new listener backend on those.