Please install Docker in advance.
$ docker pull ruby
Please change <NAME>
and <DIRECTORY>
as needed.
$ docker run -i -t --name <NAME> -p 3000:3000 -v "$PWD":<DIRECTORY> /bin/bash
Change to your working directory.
$ cd <DIRECTORY>
Next, generate a Gemfile
$ bundle init
Confirm that it has been generated.
$ ls
Gemfile
Install vim
for editing.
(You can also edit directly from the directory on the host PC)
$ apt-get install vim-tiny
Edit
Uncomment the # gem" rails "`` #
.
$ vim.tiny Gemfile
After editing
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "rails"
Install Gem.
$ bundle install
Create a new Rails project.
$ bundle exec rails new .
Install NodeJS.
$ apt-get install nodejs
I will install Webpacker, but I need Yarn
before that, so I will install it.
However, if you just apt-get install
, it will be installed with the version 0.32 + git
,
It seems that an error occurs when checking the version of yarn
that is performed when webpack: install
is performed.
** References: [[Rails] ArgumentError: Malformed version number string 0.32 + What to do if webpacker: install cannot be executed with git](https://qiita.com/TomoProg/items/9497be086d338b3b74cc#%E5%8E% 9F% E5% 9B% A0) **
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
$ apt-get update && apt-get install yarn
Install Webpacker.
rails webpacker:install
You should be able to start it.
$ bundle exec rails server
In my environment, I couldn't connect locally, so I specified it explicitly and I was able to connect successfully.
$ bundle exec rails server -b 0.0.0.0
=> Booting Puma
=> Rails 6.0.3.2 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.6 (ruby 2.7.1-p83), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Started GET "/" for 172.17.0.1 at 2020-09-07 09:47:16 +0000
Cannot render console from 172.17.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
(1.5ms) SELECT sqlite_version(*)
Processing by Rails::WelcomeController#index as HTML
Rendering /usr/local/bundle/gems/railties-6.0.3.2/lib/rails/templates/rails/welcome/index.html.erb
Rendered /usr/local/bundle/gems/railties-6.0.3.2/lib/rails/templates/rails/welcome/index.html.erb (Duration: 6.3ms | Allocations: 295)
Completed 200 OK in 21ms (Views: 12.1ms | ActiveRecord: 0.0ms | Allocations: 1651)
Yay! You're on Rails!
** References: Rails on Docker starting from knowledge 0 **
Recommended Posts