github

rails / docked

  • пятница, 16 декабря 2022 г. в 00:36:21
https://github.com/rails/docked


Running Rails from Docker for easy start to development



Docked Rails

Setting up Rails for the first time with all the dependencies necessary can be daunting for beginners. Docked Rails uses a Rails CLI Docker image to make it much easier. You can start a new Rails application, working with that application during development, and run a basic server without installing anything besides Docker on your machine.

Getting started

First install Docker (and WSL on Windows). Then copy'n'paste to run in the terminal:

docker volume create ruby-bundle-cache
alias rails='docker run --rm -it -v $PWD:/rails -v ruby-bundle-cache:/bundle ghcr.io/rails/cli'
alias rails-server='docker run --rm -it -v $PWD:/rails -v ruby-bundle-cache:/bundle -p 3000:3000 ghcr.io/rails/cli server -b 0.0.0.0'
alias rails-dev='docker run --rm -it -v $PWD:/rails -v ruby-bundle-cache:/bundle -p 3000:3000 --entrypoint bin/dev ghcr.io/rails/cli'
alias bundle='docker run --rm -it -v $PWD:/rails -v ruby-bundle-cache:/bundle --entrypoint bundle ghcr.io/rails/cli'
alias rake='docker run --rm -it -v $PWD:/rails -v ruby-bundle-cache:/bundle --entrypoint rake ghcr.io/rails/cli'
alias rails-yarn='docker run --rm -it -v $PWD:/rails -v ruby-bundle-cache:/bundle --entrypoint yarn ghcr.io/rails/cli'

Then you're ready to create your first Rails app:

rails new weblog
cd weblog
rails generate scaffold post title:string body:text
rails db:migrate
rails-server

That's it! You're running Rails with your weblog on http://localhost:3000/posts.

If you're starting a new app using jsbundling-rails, you can run rails-dev instead of rails-server.