Giter VIP home page Giter VIP logo

tasklist's Introduction

Ruby on Rails on Docker

Ruby version

Gem versions

  • Ruby on Rails Gem Version

  • rubocop Gem Version

Setup Dockerized development environment

  • Docker環境をローカルマシンに作成
  • bundlerでFWなどのパッケージを導入して使用する想定
  • RDBMSはPostgreSQLとする

Installation

Docker for Mac, Docker for Windows

dockerコマンド、docker-machineコマンド、docker-composeコマンド全部入り

In case of Mac, You can also use Homebrew

$ brew install docker
$ brew cask install docker

Initial Setting

Launch Docker Host OS(docker-machineをつかう場合だけ必要)

$ docker-machine create --driver virtualbox myrailsapp
$ docker-machine start myrailsapp

起動を確認

$ docker-machine ls

接続

$ docker-machine env myrailsapp

# Run this command to configure your shell:と出力されるので従う

Gemfile確認

DefaultではRuby on Rails最低限のGemのみ記載 この上に必要なGemを追加していきます。

Docker Container build

docker-composeコマンドを使い、複数コンテナをbuild〜起動していく

コンテナ構成

  • app
  • db
  • node(初期は使わないので削除してもよい)

(設定はdocker-compose.yml)

$ docker-compose build
Successfully built.

Generation packages by rails new

$ docker-compose run --rm app rails new . -d postgresql --skip-bundle --skip-turbolinks --skip-test --skip

起動

$ docker-compose up -d

コンテナの起動確認

$ docker ps

データベースのConnection設定

生成されたconfig/database.ymldevelopment: 配下に

database: <%= ENV['PG_DATABASE'] %>
username: <%= ENV['PG_USER'] %>
password: <%= ENV['PG_PASSWORD'] %>
host: db

を追加修正 ** postgresのdockerイメージは起動時に初期DBや初期ユーザをよしなに作成してくれることを留意しておく **

postgresイメージに渡せる環境変数の参照

設定変更後はコンテナを再起動する

$ docker-compose restart app

ブラウザでRailsの起動確認

$ open http://0.0.0.0

docker-machineの場合

$ open http://$(docker-machine ip myrailsapp)

Railsの初期画面が表示されればSetup Complete

Gemfileに変更があった場合

変更をローカルにマージ後

$ docker-composer build

buildし直すことで、DockerfileのAddがGemfile&Gemfile.lockのキャッシュから更新があったときのみ検知してbundle install が走る

既存問題点

Docker machine のホスト時刻がずれて、Railsの更新が反映されない問題

http://qiita.com/pocari/items/456052a291381895f8b3

Dockerマシンの中に入って

$ docker-machine ssh ****

VirualBoxの設定変更

$ sudo VBoxControl guestproperty set "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 5000

Docker inorify issue

reach limit of inotify count in rails console Error Message

Increasing the amount of inotify watchers

$ echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf && sysctl -p
$ cat /proc/sys/fs/inotify/max_user_watches

Dockerfileに組み込みたいが、Privilegedで起動扠せねばならぬ問題があるため、起動時に叩くシェルを作るか

tasklist's People

Contributors

kaitoimai01 avatar hihats avatar jose-hirayama avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.