LoginSignup
6
7

More than 5 years have passed since last update.

docker-composeを利用したRails5アプリでbootstrap4を使う

Last updated at Posted at 2017-11-14

ソース一式はこちらにあるので、docker-composeやGemfile, application.scssの設定等ご参考ください。
https://github.com/mom0tomo/todo-list

環境

  • macOS Sierra
  • docker for Mac 17.09.0-ce
  • Ruby 2.4.2
  • Rails 5.1.3

導入方法

docker-composeでRails5開発環境構築

公式の通りに進めます。
https://docs.docker.com/compose/rails/#define-the-project

Rails5でbootstrap4を使う

bootstrap4を利用するためにtwbs/bootstrap-rubygemを使います。

公式の通りに進めます。
https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails

公式では上記手順を踏めばbootstrap4が使えることになっていますが、私の環境では下記のエラーが出てしまいました。

発生したエラー

File to import not found or unreadable: bootstrap

bootstrapが読み込めないと言われています。

スクリーンショット 2017-11-14 9.28.10.png

$ docker-compose up -d してもダメ。upしなおすと、web(アプリ)のコンテナがステータス1で異常終了、落ちてしまいます。

対処法

コンテナをbuildし直して再起動し直したら適用されました。

$ docker-compose build

$ docker-compose ps
     Name                   Command               State           Ports
--------------------------------------------------------------------------------
todolist_db_1    docker-entrypoint.sh postgres    Up      5432/tcp
todolist_web_1   bundle exec rails s -p 300 ...   Up      0.0.0.0:3003->3000/tcp

build、再起動してもエラーが出たら、もう一度再起動してみます。

$ docker-compose up -d

原因

rebuildしなければいけないのはDockerfileを更新したときだけだと思っていましたが、Gemfileを更新したときも $ docker-compose buildし直さなければいけないとのこと。

公式に書いてあったのに見逃していました。

Now that you’ve got a new Gemfile, you need to build the image again. (This, and changes to the Gemfile or the Dockerfile, should be the only times you’ll need to rebuild.)

まとめ

docker-composeを使ったRailsアプリ開発では、Gemfileを更新したときbuildしなおす必要がある。

参考リンク

回避する方法もあるそうです。
docker-composeでRailsのGemを更新する時、docker buildするのを回避したい | Qiita

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