LoginSignup
0
0

More than 3 years have passed since last update.

Rails アプリケーション作成手順

Last updated at Posted at 2020-08-09

概要

Dockerを使ってRails開発を始めれるように自分用のメモとして作成しました。
使用するDBはmysqlです。

1.アプリケーション用のbuild contextを作成

フォルダの名前:アプリケーション名
build context内:Dockerfile, docker-compose.yml, Gemfile Gemfile.lock
を作成します。

2.rails new を実行する

コマンド
$docker-compose run web rails new . --force --database=mysql --skip-bundle

3.database.ymlを編集する

database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: password # docker-compose.ymlのMYSQL_ROOT_PASSWORD
  host: db # docker-compose.ymlのservice名

4.docker buildしてGEMを読み込む

コマンド
# コンテナをビルド
$ docker-compose build 

# コンテナを起動
$ docker-compose up -d

DBを作成

コマンド
$ docker-compose run web rails db:create

ブラウザでlocalhost:XXXXにアクセスしてサーバ起動を確認する。

スクリーンショット 2020-08-09 16.18.37.png

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