Fixing Automatic Reload of Code Changes in Ruby on Rails While Using Docker

May 18, 2018

Ruby on Rails has a very useful feature that reloads source code when changes are made while in development mode. This allows us to keep the development server running while modifying the code, instead of having to restart the server after every change.

I’ve recently started using Docker and Docker Compose for local development which has been a huge productivity boon. Unfortunetely, out of the box, Ruby on Rails doesn’t seem to be auto-reloading my applications when using Docker. Luckily, a one line configuration change is all that is needed to get this great feature working again.

To make code auto-reloading work, in config\environments\development.rb simply replace

config.file_watcher = ActiveSupport::EventedFileUpdateChecker


config.file_watcher = ActiveSupport::FileUpdateChecker

Now you just need to stop your application and start it again with docker-compose up, or however you’re running your dockerized application. Now anytime you make changes to models, controllers, or any other Ruby code the changes should take affect without the need to manually restart your application.

My RSS reader Bulletin is an example of an application that previously exhibited this behaviour but has been fixed with this solution.