6
5

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 5 years have passed since last update.

Rails on Dokcer on boot2docker構成でlivereloadする方法

Posted at

環境

  • browser(Chrome 41.0.2272.118 (64-bit))
  • livereload(2.0.3)
  • guard-livereload(2.4.0)
  • boot2docker(1.5.0)
  • docker(1.5.0)
  • Rails(4.2.1)
  • GuestOS(CentOS Linux release 7.0.1406 (Core))
  • HostOS(Mac OS X 10.10.2)

構成

構成は以下の通り。
- guardサーバーが35729をListenしてる
- Dockerが35729をExposeしてる
- boot2dockerの35729をDockerの35729へforwarding
- HostのMac OSの35729をboot2dockerの35729へforwarding

 -----
|guard|  Listen:35729 
 -----
 ------
|Docker| 0.0.0.0:35729->35729/tcp 
 ------
 -----------
|boot2docker| 
 -----------
 ------
|Mac OS| ssh -L 35729:localhost:35729
 ------

手順

guard, guard-livereloadの設定

インストールや初期設定の手順は他にたくさん説明があるので割愛。

guard 'livereload', host: '0.0.0.0', port: '35729' do
  watch(%r{app/views/.+\.(erb|haml|slim)$})
  watch(%r{app/helpers/.+\.rb})
  watch(%r{public/.+\.(css|js|html)})
  watch(%r{config/locales/.+\.yml})
  # Rails Assets Pipeline
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end

Docker

起動オプションでforwardingを設定する

% docker run --volumes-from dev -p 35729:35729 -p 2222:22 -p 80:3000 -itd osamunmun/dev:1.1 /usr/sbin/sshd -D

boot2docker, Mac OS

% boot2docker ssh -L 35729:localhost:35729

確認

guardのconsoleに以下のようなlogが表示されたら接続成功。

[1] guard(main)> 16:19:32 - INFO - Browser connected.
6
5
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
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?