Vite Rails running on Docker
A minimal example on how to configure Docker to run a Vite.js process alongside a Rails app.
The integration is powered by Vite Rails.
To prepare the Docker image, run:
docker-compose build
To start the Rails and Vite services, run:
docker-compose up
Once you have started both services, you can verify that the Vite dev server can be reached from Rails by running:
docker-compose run --rm --entrypoint "bin/rails c" rails
and then:
> ViteRuby.instance.dev_server_running?
=> true
Now that you have learned the basics, please follow this guide instead for a more comprehensive configuration:
At the time of writing, the guide covers how to use Webpacker, but configuring Vite Rails should be very similar:
- Use
bundle exec ./bin/vite dev
instead ofbundle exec ./bin/webpack-dev-server
- Expose port
3036
instead of3035
- Rename the
webpacker
service tovite
- Rename
WEBPACKER_DEV_SERVER_HOST
toVITE_RUBY_HOST
:- Including
WEBPACKER_DEV_SERVER_HOST: webpacker
toVITE_RUBY_HOST: vite
- Including