Docker 为 webpacker_dev_server 加载了不正确的端口
Docker loaded incorrect port for webpacker_dev_server
我正在学习将 rails 5 部署到 docker。一切正常,直到我安装了 React webpacker。它似乎试图连接到错误的端口并导致反应故障。
我已经尝试在 development:dev_server:host = 0.0.0.0 下更新 config/webpacker.yml,但仍然无法正常工作
错误日志如下
web_1 | #<SocketError: Failed to open TCP connection to webpack_dev_server:3035:80 (getaddrinfo: Name or service not known)>
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:949:in `rescue in block in connect'
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:946:in `block in connect'
web_1 | /usr/local/lib/ruby/2.6.0/timeout.rb:93:in `block in timeout'
web_1 | /usr/local/lib/ruby/2.6.0/timeout.rb:103:in `timeout'
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:945:in `connect'
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:930:in `do_start'
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:925:in `start'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/http_streaming_response.rb:71:in `session'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/http_streaming_response.rb:60:in `response'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/http_streaming_response.rb:29:in `headers'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:120:in `perform_request'
web_1 | /usr/local/bundle/gems/webpacker-3.6.0/lib/webpacker/dev_server_proxy.rb:20:in `perform_request'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
web_1 | /usr/local/bundle/gems/railties-5.2.4.3/lib/rails/engine.rb:524:in `call'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/configuration.rb:227:in `call'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:706:in `handle_request'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:476:in `process_client'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:334:in `block in run'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
这是我的 docker-compose.yml
内容:
services:
web:
build: .
ports:
- 3000:3000
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=webpack_dev_server
webpack_dev_server:
build: .
command: ./bin/webpack-dev-server
ports:
- 3035:3035
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
redis:
image: redis
database:
image: postgres
env_file:
- .env/development/database
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
我的 Gemfile 是
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.6'
gem 'rails', '~> 5.2.4', '>= 5.2.4.3'
gem 'pg', '~> 1.0'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'redis', '~> 4.0'
gem 'webpacker', '~> 3.5'
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
希望你一切顺利。
最近我遇到了和你一样的问题,我得到了以下错误:
#<SocketError: Failed to open TCP connection to webpack_dev_server:3035:80 (getaddrinfo: Name or service not known)>
经过一番研究,我找到了Kota Miyake的博客,他也遇到了同样的问题。
基本上,您只需将 webpack_dev_server
服务名称更改为 webpack-dev-server
。因此,您的 docker-compose.yml
将变成如下所示:
services:
web:
build: .
ports:
- 3000:3000
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=webpack_dev_server
webpack-dev-server:
build: .
command: ./bin/webpack-dev-server
ports:
- 3035:3035
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
redis:
image: redis
database:
image: postgres
env_file:
- .env/development/database
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
注意:如果您在其他地方引用了 webpack_dev_server
,您可能还需要重命名它。
请查看 Kota Miyake's blog 了解更多详情。
希望对您有所帮助。
此致,
我正在学习将 rails 5 部署到 docker。一切正常,直到我安装了 React webpacker。它似乎试图连接到错误的端口并导致反应故障。
我已经尝试在 development:dev_server:host = 0.0.0.0 下更新 config/webpacker.yml,但仍然无法正常工作
错误日志如下
web_1 | #<SocketError: Failed to open TCP connection to webpack_dev_server:3035:80 (getaddrinfo: Name or service not known)>
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:949:in `rescue in block in connect'
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:946:in `block in connect'
web_1 | /usr/local/lib/ruby/2.6.0/timeout.rb:93:in `block in timeout'
web_1 | /usr/local/lib/ruby/2.6.0/timeout.rb:103:in `timeout'
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:945:in `connect'
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:930:in `do_start'
web_1 | /usr/local/lib/ruby/2.6.0/net/http.rb:925:in `start'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/http_streaming_response.rb:71:in `session'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/http_streaming_response.rb:60:in `response'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/http_streaming_response.rb:29:in `headers'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:120:in `perform_request'
web_1 | /usr/local/bundle/gems/webpacker-3.6.0/lib/webpacker/dev_server_proxy.rb:20:in `perform_request'
web_1 | /usr/local/bundle/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
web_1 | /usr/local/bundle/gems/railties-5.2.4.3/lib/rails/engine.rb:524:in `call'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/configuration.rb:227:in `call'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:706:in `handle_request'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:476:in `process_client'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:334:in `block in run'
web_1 | /usr/local/bundle/gems/puma-3.12.6/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
这是我的 docker-compose.yml
内容:
services:
web:
build: .
ports:
- 3000:3000
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=webpack_dev_server
webpack_dev_server:
build: .
command: ./bin/webpack-dev-server
ports:
- 3035:3035
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
redis:
image: redis
database:
image: postgres
env_file:
- .env/development/database
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
我的 Gemfile 是
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.6'
gem 'rails', '~> 5.2.4', '>= 5.2.4.3'
gem 'pg', '~> 1.0'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'redis', '~> 4.0'
gem 'webpacker', '~> 3.5'
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
希望你一切顺利。
最近我遇到了和你一样的问题,我得到了以下错误:
#<SocketError: Failed to open TCP connection to webpack_dev_server:3035:80 (getaddrinfo: Name or service not known)>
经过一番研究,我找到了Kota Miyake的博客,他也遇到了同样的问题。
基本上,您只需将 webpack_dev_server
服务名称更改为 webpack-dev-server
。因此,您的 docker-compose.yml
将变成如下所示:
services:
web:
build: .
ports:
- 3000:3000
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=webpack_dev_server
webpack-dev-server:
build: .
command: ./bin/webpack-dev-server
ports:
- 3035:3035
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
redis:
image: redis
database:
image: postgres
env_file:
- .env/development/database
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
注意:如果您在其他地方引用了 webpack_dev_server
,您可能还需要重命名它。
请查看 Kota Miyake's blog 了解更多详情。
希望对您有所帮助。
此致,