Rails on Docker environment construction procedure

environment

procedure

Please install Docker in advance.

Get Ruby image

$ docker pull ruby

Launch Docker container

Please change <NAME> and <DIRECTORY> as needed.

$ docker run -i -t --name <NAME> -p 3000:3000 -v "$PWD":<DIRECTORY> /bin/bash

Introducing Rails

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

Start Rails Server

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!

image.png

end

** References: Rails on Docker starting from knowledge 0 **

Recommended Posts

Rails on Docker environment construction procedure
Rails Docker environment construction
[Docker] Rails 5.2 environment construction with docker
Rails + MySQL environment construction with Docker
Ruby on Rails 6.0 environment construction memo
[Environment construction with Docker] Rails 6 & MySQL 8
Docker environment construction
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
Rails environment construction with Docker (personal apocalypse)
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Muscle Ruby on Rails Day 1 ~ Environment Construction ~
"Rails 6 x MySQL 8" Docker environment construction procedure for sharing with teams
Environment construction command memo with Docker on AWS
Rails6 [API mode] + MySQL5.7 environment construction with Docker
[Personal memo] Ruby on Rails environment construction (Windows)
Ruby on Rails development environment construction on M1 Mac
Wordpress local environment construction & development procedure with Docker
Rails6 development environment construction [Mac]
Rails engineer environment construction ruby2.7.1
Rails environment construction Rails5.2.1 ruby2.5.1 Catalina
MySQL 5.7 (Docker) environment construction memo
Redmine (Docker) environment construction memo
Docker × Spring Boot environment construction
[Rails / MySQL] Mac environment construction
[Docker] postgres, pgadmin4 environment construction
React environment construction with Docker
[Environment construction] Ruby on Rails 5.2 system development environment construction [within 1 hour]
virtulbox + vagrant + Docker + nginx + puma + MySQL Rails environment construction
Deploy to Ruby on Rails Elastic beanstalk (Environment construction)
[Environment construction Mac] Ruby on Rails (+ Webpacker handles errors)
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
Node.js environment construction with Docker Compose
From 0 to Ruby on Rails environment construction [macOS] (From Homebrew installation to Rails installation)
Environment construction with Docker for beginners
Laravel + Docker Laradock usage environment construction
[Unity] Android development environment construction procedure
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
[Environment construction] Get the Ruby on Rails 6 development environment within 1 hour
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
CentOS8 + Anaconda 4.9.2 + jupyterhub environment construction procedure
Deploy Rails on Docker to heroku
Troublesome Rails environment construction flow [Windows 10]
Build Unity development environment on docker
[Environment construction] Uninstall rails from local
[Rails] AWS EC2 instance environment construction
Ruby on Rails --From environment construction to simple application development on WSL2
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
[Note] Docker version Db2 environment acquisition procedure
SQL statement learning ~ Environment construction ~ Docker + MySQL
CentOS8 + Anaconda + Django development environment construction procedure
GPU environment construction with Docker [October 2020 version]
Building Rails 6 and PostgreSQL environment with Docker
Spring Boot environment construction memo on mac
Laravel development environment construction with Docker (Mac)
Sapper × Go (echo) × Docker development environment construction
Create Rails 6 + MySQL environment with Docker compose
Java development environment construction memo on Mac
Migrate existing Rails 6 apps to Docker environment
Use docker in proxy environment on ubuntu 20.04.1