[Rails] Docked Rails - Running Rails from Docker for easy start to development
Rails released a new official repository rails/docked on GitHub to help beginners to run 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, requiring only Docker to be installed.
Getting started
First install Docker (and WSL on Windows). Then copy’n’paste into your terminal:
1 | docker volume create ruby-bundle-cache |
Then create your Rails app:
1 | rails new weblog |
That’s it! You’re running Rails on http://localhost:3000/posts
.
More
Of course you can also choose to enter a Docker container to create and run your Rails application. (Note the location of the --entrypoint /bin/bash
parameter.)
1 | docker run --rm -it --entrypoint /bin/bash -v $PWD:/rails -v ruby-bundle-cache:/bundle ghcr.io/rails/cli |
Run the following command after entering the container: (Note that the -b 0.0.0.0
parameter is specified in the last command.)
1 | rails new weblog |
BTW, Using a Docker container to run an Rails application in a virtualized Linux environment (such as macOS, Windows) may be slower than running the same application directly.
References
[3] Package cli - https://github.com/orgs/rails/packages/container/package/cli