'Why aren't changes to Rails files being reflected inside Docker container?
I'm new to Rails and running a Rails app via Docker (on Windows/WSL2) and it seems any changes I make in controllers (and possibly elsewhere) are not reflected until I restart my container.
For example, if I delete the entire contents of a controller file, then refresh, there's no change. If I restart my container and then refresh, I get nice big red Rails errors, which is what I would expect.
What I've tried/checked:
- That the right environment is being loaded - calling
Rails.envon the Rails CLI (inside the container) yields "development" - That the
cache_classesconfig option is set tofalseinside thedevelopment.rbenvironment file. I've also confirmed this via the Rails CLI viaRails.application.config.cache_classes- yields "false".
Here's my compose file (truncated):
web:
container_name: web
env_file: .env
build:
context: .
dockerfile: Dockerfile
command: /bin/sh -c "rm -f /app/tmp/pids/server.pid && gem install bundler -v 2.2.21 && bundle install && rails db:migrate && rails server --port 3000 --binding 0.0.0.0"
ports:
- 3000:3000
- 5432:5432
- 2222:2222
volumes:
- ../:/app
- bundle:/usr/local/bundle
- rails_cache:/app/tmp/cache
- node_modules:/app/node_modules
profiles:
- app
- appnm
Anyone see what's up?
Solution 1:[1]
Turns out I needed to change the following in config/environments/development.rb:
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
to
config.file_watcher = ActiveSupport::FileUpdateChecker
Why this isn't in the development env file by default, I've no idea. Surely the whole point of a development environment is to allow high-frequency file edits be reflected in the app as they happen!
Solution 2:[2]
Fixed this by launching devtools like this: npx react-devtools
(The problem occurs when I launch devtools like this: react-devtools)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user9540234 |
| Solution 2 | David |
