,

Using Ngrok with Rails

When working with Rails, I like to test my web apps with my desktop browser and my mobile browser. I like using my mobile browser, especially to test the PWA setup.

To be able to test the development version running in Docker with my devcontainer setup, I use Ngrok.

You need to register and install the CLI from here https://dashboard.ngrok.com/get-started/setup/linux

Once you have ngrok installed in your Docker container, you can setup your Rails app to allow connections from Ngrok urls. Open config/environments/development.rb and add the following line:

  config.hosts << '.ngrok-free.app'

Start your Rails server as usual, and then on a new console run:

ngrok http http://localhost:3000

Ngrok will give you a public URL you can use on your phone to connect directly to your docker container.

Enjoy ✌️


About the Author

Ivan Morgillo is a freelance software developer and technical trainer with 15+ years of experience. He has worked with Google, JetBrains, Bending Spoons, Deutsche Bahn, OneFootball, and The Body Coach. He specialises in Android, Flutter, Ruby on Rails, and AI integration. Follow him on Twitter @hamen or watch his coding content on YouTube @codewiththeitalians.