rails: Code is not reloaded in dev with Docker on OS X
Steps to reproduce
- Install the Docker toolbox on OS X. Here are my instructions to install it with brew.
- Clone https://github.com/jeromedalbert/rails_5_rc1_docker. I have created this dummy application specifically for this issue.
- Follow the short instructions to set up the project and have a server running.
- Open the application in your browser.
- While the server is running, edit
app/controllers/static_controller.rb
and change'hello world!'
to'coconut'
. - 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
- Introduce a new environment for docker to rails Rails does not play well with docker with due to not supporting events telling ruby a file changed. The docker config tells rails to poll files rather ... — committed to barnardos/consent-form-builder by ztolley 7 years ago
- Turn off evented reload. https://github.com/rails/rails/issues/25186 — committed to knpwrs/pco-graphql by knpwrs 7 years ago
- chore: being able to reload automatically See: https://github.com/rails/rails/issues/25186#issuecomment-530275858 — committed to 5000164/dialog by 5000164 3 years ago
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):
@mrkongo Go to config/environments/development.rb and comment
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 toFileUpdateChecker
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
toFileUpdateChecker
.[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: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.