The original article is reprinted from Liu Yue’s Technology Blog

In 2020, the “not-so-famous Web framework” Ruby on Rails will be 15 years old. This year, Rails 6.0 has been perfected, Webpacker has become the default front-end packaging solution, and Sprockets have begun a soft landing. It is very likely that one day, along with jQuery, Sprockets will be completely deprecated.

For historical reasons, Homebrew, which was written in Ruby itself, was very popular on the Mac OS, so most Rails programmers have a Mac Book Pro as their primary computer, while Windows users are not so lucky. Rails 6.0, for example, started enabling Webpacker, which required users to install YARN, which had a ripple effect, as well as the desperate CoffeeScript issue with Windows 10, which is one of the things that Rails, including Jekyll, often complained about: Why don’t I use Django, Laravel, or Spring Boot when setting up an environment takes so much work? Why do I have to suffer this? Because… Love, this time we use Docker to simplify the construction of the Rails environment, so that it can achieve seamless development under various operating systems.

Of course, the first step is to install Docker. If you don’t have Docker Toolbox installed, please refer to: play with DockerToolbox under Win10 system and replace the domestic mirror source (all kinds of chars).

Then create a directory of Rails projects on your computer

mkdir myr  
cd myr

Third, pull the base image, which has Ruby2.5.1 and Node11 built in, to set the stage for installing Rails6.0

docker pull starefossen/ruby-node

After successfully pulling the image, start the container and go to the command line. Remember to use the mount command to share the current directory into the Docker container. For those who do not know how to set the shared folder, please refer to this post: Windows 10 system based on Docker configuration ElasticSearch7 with Python3 for full text search interaction

docker run --rm -v /myr:/usr/src -w /usr/src -ti starefossen/ruby-node /bin/bash

Since Ruby2.5.1 is already installed inside the container, and so is the gem, we can install Rails inside Easy

Gem install -v 6.0.2 rails

Version number is controlled here with the -v parameter.

After successfully installing Rails6.0 in the container, create the project directly in the container

rails new .

Once the project is set up, you’ll notice that the Rails project files appear synchronously in the Windows directory

At this point, type exit on the container command line to exit the container, and the container will stop and be deleted. The container has completed its historical purpose, which is to create a Rails project and synchronize it with the host via shared files.

Next, in order to run our Rails service on the host, we need a Dockerfile to customize our own image

/ RUN bundle install # COPY Gemfile*./ RUN bundle install # COPY Gemfile./ # CMD ["bundle", "exec", "rails", "server", "-b", ""]

After writing the Dockerfile, we can create a new image that will run our existing Rails project.

docker build -t myr .

After successful packaging, type the command to view the image

docker images

At this point, start the container

docker run -p 3000:3000 -v /myr:/usr/src/app/ myr

Go to http://localhost:3000

The familiar “world people united” welcome page has been greeted, it is so simple, someone said, Python is now the “hot chicken”, now learning Rails will be “1949 to join the army”? I would say that Rails is still powering more than 100 million websites and back-end services around the world this year, including some of the world’s most famous companies, such as: Airbnb, Basecamp, GitHub, etc. While PHP and Python are more widely used than Ruby, the two most popular frameworks, Laravel and Django, have far fewer code contributors than Rails, respectively. More open source contributors mean that the quality of Gem is very good. As the saying goes, Gem gives everything to Rails, which is often praised because the community that supports it is working hard to create a lot of reusable libraries.

We can look at the number of open source contributors on GitHub for comparison:

GitHub contributors to Ruby frameworks:

Rails: 4260

Padrino: 228

Hanami: 146

Sinatra: 387

GitHub contributors to Django (Python) and Laravel (PHP):

Django: 2007 Laravel: 740

The gap can be seen, in the final analysis, the development and use of a framework or to “people” oriented. As always, focused on the Web, focused on the products of Rails6.0 in the new era will carry on the past and create brilliance.

The original article is reprinted from Liu Yue’s Technology Blog