1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dockerでRails6開発環境構築

Last updated at Posted at 2020-07-04

紹介する内容

  • rails6開発環境をdockerでrails newから構築します
    • rails6.0.3.2です

結論

  • rails6開発環境をdockerでrails newから構築するなら、Dockerfileやentrypointの内容作成タイミングに気を付ける必要があります

紹介始めます

ディレクトリ構成

全体ソースコードは https://github.com/cheekykorkind/qiita-example/tree/master/rails/6/puma で確認できます

  • 全体図
    allD.png

  • rails new . -d postgresqlで生成された部分
    railsNew.png

Rails6プロジェクト作成までの手順です

docker composeがあるデレクトリーに移動しました

  • cd qitta-example/rails/6/puma

Dockerfileとentrypoint.shにdbマイグレーション、puma起動コマンド部分なしで、rails起動させるdockerコンテナを起動しました

  • railsをインストールするためです
  • railsがインストールされてない状態でentrypoint.shのbundle execコマンドでdb:create db:migraterails s -p 3000 -b 0.0.0.0などを行したらエラーになるからです
    • rails newコマンドを実行するタイミングで使ったDockerfileファイル
      commentoutDockerfile.png

    • rails newコマンドを実行するタイミングで使ったentrypoint.shファイル
      commentoutEntrypoint.png

rails起動させるdockerコンテナに入りました

  • DOCKER_UID=$(id -u $USER) DOCKER_GID=$(id -g $USER) docker-compose up -d
  • docker exec -it rails-puma-web /bin/bash

rails newコマンドでインストールしました

  • rails new . -d postgresql
  • postgres使いますからrails newコマンドにpostgresを含めました

database.ymlを修正しました

  • hostをdocker composeに合わせて調整しました
  • 他の部分も調整しました

Dockerfileとentrypoint.shにdbマイグレーション、puma起動コマンドを追加しました

  • railsがインストールされたから、dbマイグレーション、puma起動コマンドが問題なく起動できます

Rails6動きました

実行コマンドです

cd qitta-example/rails/6/puma
DOCKER_UID=$(id -u $USER) DOCKER_GID=$(id -g $USER) docker-compose up

railsPuma.gif

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?