Dockerでwebpacker 3.0 が動かない時にやったこと


# 概要
* webpacker3.0とともにrailsの環境をdockerに構築したところ、webpacker_dev_serverに接続できないエラーが発生した。
* 解決方法は、webpacker-dev-serverに接続できるポート（0.0.0.0）を指定するだけ。

# 環境
[これ](http://qiita.com/KazuyaHara/items/17c0e2f745ad48b0f0f3)と[この](http://qiita.com/junara/items/ae09c94da5223c9c3aff)サイトをもとにしてrailsの開発環境をdockerで構築。主な違いはwebpackerのversionが3.0である点。

```ruby
gem 'webpacker', '~> 3.0' #  '~> 2.0'ではない
```

# エラー内容
構築したdockerイメージを起動させ、locahost:3000にアクセスしたところ下記のエラーがでた。

```
web_1  | Processing by Rails::WelcomeController#index as HTML
web_1  |   Rendering /usr/local/bundle/gems/railties-5.1.3/lib/rails/templates/rails/welcome/index.html.erb
web_1  |   Rendered /usr/local/bundle/gems/railties-5.1.3/lib/rails/templates/rails/welcome/index.html.erb (2.6ms)
web_1  | Completed 200 OK in 7ms (Views: 5.4ms)

web_1  | 2017-09-06 12:45:53 +0000: Rack app error handling request { GET / }
web_1  | #<Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for [::1]:3035>
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:1198:in `__connect_nonblock'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:1198:in `connect_nonblock'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:56:in `connect_internal'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:137:in `connect'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:627:in `block in tcp'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:227:in `each'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:227:in `foreach'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:617:in `tcp'
web_1  | /usr/local/bundle/gems/webpacker-3.0.1/lib/webpacker/dev_server.rb:9:in `running?'
web_1  | /usr/local/bundle/gems/webpacker-3.0.1/lib/webpacker/dev_server_proxy.rb:7:in `rewrite_response'
web_1  | /usr/local/bundle/gems/rack-proxy-0.6.2/lib/rack/proxy.rb:57:in `call'
web_1  | /usr/local/bundle/gems/railties-5.1.3/lib/rails/engine.rb:522:in `call'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/configuration.rb:225:in `call'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/server.rb:605:in `handle_request'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/server.rb:437:in `process_client'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/server.rb:301:in `block in run'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
web_1  | 2017-09-06 12:45:54 +0000: Rack app error handling request { GET /favicon.ico }
web_1  | #<Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for [::1]:3035>
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:1198:in `__connect_nonblock'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:1198:in `connect_nonblock'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:56:in `connect_internal'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:137:in `connect'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:627:in `block in tcp'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:227:in `each'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:227:in `foreach'
web_1  | /usr/local/lib/ruby/2.4.0/socket.rb:617:in `tcp'
web_1  | /usr/local/bundle/gems/webpacker-3.0.1/lib/webpacker/dev_server.rb:9:in `running?'
web_1  | /usr/local/bundle/gems/webpacker-3.0.1/lib/webpacker/dev_server_proxy.rb:7:in `rewrite_response'
web_1  | /usr/local/bundle/gems/rack-proxy-0.6.2/lib/rack/proxy.rb:57:in `call'
web_1  | /usr/local/bundle/gems/railties-5.1.3/lib/rails/engine.rb:522:in `call'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/configuration.rb:225:in `call'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/server.rb:605:in `handle_request'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/server.rb:437:in `process_client'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/server.rb:301:in `block in run'
web_1  | /usr/local/bundle/gems/puma-3.10.0/lib/puma/thread_pool.rb:120:in `block in spawn_thread'

```

## 詳しく見ると
普通のhtmlのレンダリングは成功している。

```
web_1  |   Rendered /usr/local/bundle/gems/railties-5.1.3/lib/rails/templates/rails/welcome/index.html.erb (2.6ms)
web_1  | Completed 200 OK in 7ms (Views: 5.4ms)
```

なんか、webpackerのdev_serverが怪しい

```
web_1  | /usr/local/bundle/gems/webpacker-3.0.1/lib/webpacker/dev_server.rb:9:in `running?'
web_1  | /usr/local/bundle/gems/webpacker-3.0.1/lib/webpacker/dev_server_proxy.rb:7:in `rewrite_response'
```

# 解決方法
##原因

https://github.com/rails/webpacker/blob/master/README.md#development の記述を読むと、ポートが問題であることが推測された。

そのため、下記の様にlocalhost -> 0.0.0.0に修正することで解決する事ができた。

```config/webpacker.yml
 dev_server:
    host: 0.0.0.0
    port: 3035
    hmr: false
    https: false
```