LoginSignup
0
0

More than 1 year has passed since last update.

[メモ] Docker「ruby:3.0-slim-buster」に Rails6 (簡素版) を導入してみる (Django使用経験あり)

Last updated at Posted at 2021-09-10

概要

「Ruby経験あり、Rails 経験なし、JavaScript アプリ開発経験なし」の観点で、
御著書 『Railsの教科書』 で Rails6 の学習をしてみたときの記録である.

このとき、Dockerイメージ「ruby:3.0-slim-buster」に対して Rails6 を導入してみたので、
書き残しておく. また、Django を用いたバックエンド開発経験はあるので、その視点でメモも
書いてみた.

なお、ここでの "簡素版" とは「Nginx や PostgreSQL や Unicorn などは導入しない」1 という意味である.

 

手順のみ

実行時の UID は root である.
なお、「ruby:3.0-slim-buster」 は Debian 10 なので、Ubuntu 18.04 にも転用できるはずである.

基本的には次の公式ドキュメントの手順を実施するのだが、少し補足してみた.
https://guides.rubyonrails.org/getting_started.html

#!/bin/bash
apt update -y
apt install -y autoconf bison build-essential libssl1.1 libyaml-dev \
               libreadline-dev zlib1g-dev libncurses5-dev libffi-dev \
               libgdbm-dev sqlite3 libsqlite3-dev

apt install -y curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

cat <<'EOL' | tee -a > $HOME/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
EOL

. $HOME/.bashrc

nvm install --lts
npm install -g yarn
gem install rails

手順 + 個人的メモあり

#!/bin/bash
apt update -y

# 推測混じりになるが、SQLite3 インストールに加えて、DB操作 (SQLクエリ発行やマイグレーション) や、
# SSL通信に必要なパッケージをインストールしているのだろう.
apt install -y autoconf bison build-essential libssl1.1 libyaml-dev \
                    libreadline-dev zlib1g-dev libncurses5-dev libffi-dev \
                    libgdbm-dev sqlite3 libsqlite3-dev

apt install -y curl

# NVM のインストールをする. 後段の Node.js と npm をインストールするため. (後述の「補足」を参照)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

# NVM を使うための設定を $HOME/.bashrc に追記する.
cat <<'EOL' | tee -a > $HOME/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
EOL

# NVM を使うための設定を有効にする
. $HOME/.bashrc

# Node.js をインストールすると、同時に npm もインストールされる. (後述の「補足」を参照)
nvm install --lts

# npm を使って Yarn をインストールする (yarn -v でバージョン表示されればOK)
npm install -g yarn

# rails をインストールする (Django における pip install Django に相当する)
# rails -v でバージョン表示されればOK
gem install rails

補足

項目 URL
npm, nvm, Node.js のメモ https://qiita.com/robozushi10/items/f8e1e2cae94f87b98acc
npm, nvm, yarn のメモ https://qiita.com/robozushi10/items/fabbd40e560557c7394e

参考にした情報

書籍

書籍 URL
『Railsの教科書』 https://railstutorial.jp/textbook

記事

URL
https://qiita.com/ashketcham/items/48d64e960d436f8b6f78
https://qiita.com/pharma_tech3/items/2ab578eb5b07ff0ca296
https://qiita.com/GalaxyNeko/items/630ac869d3bbbe93034b
https://qiita.com/masatwork/items/1b5d190cc76f5eeffbb7

以上


  1. Rails 詳細は不明だが、Django でも Nginx, PostgreSQL, Gunicorn の組み合せがあるので、推測可能である 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0