- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用sinatra用ruby编写了一个简单的Web服务。如果我运行ruby app.rb
,它将在localhost:4567上运行。我编写了一个Dockerfile来制作镜像并公开端口4567。
但是,当我运行docker image时,Web服务会运行,但是如果我尝试使用curl和浏览器连接到端口4567,它会显示Connection reset by peer
。
有人有什么建议吗?因为我不知道在这种情况下要检查什么。我已经尝试过一些模糊的东西,但是仍然..
Web服务通常在docker外部运行。
编辑1:
我已将图片推送到eivor/ruby
。如果您运行它并转到浏览器进行检查,则会显示connection reset
。是的,我在发布问题之前尝试了docker run -p 4567:4567 eivor/ruby
。
编辑2:这是app.rb
require 'sinatra'
require 'referal' # this is the gem that calculate reward points to users
require 'json'
require 'byebug'
get '/' do
'hello, world!'
end
# inside docker image, even get / returns connection reset by peer
# not to mention post data to it
post '/' do
data = JSON.parse(request.body.read)
input = []
data.each do | key, value |
input << value
end
invs, users = input.reduce([[],[]]) do | results, instruction |
results = classify(instruction, results[0], results[1])
results
end
res = export(users)
# byebug
puts res
end
post '/text' do
@data = request.body.readlines
#byebug
@processed = @data.map{ |s| process(s) }
@invs, @users = @processed.reduce([[],[]]) do | results, instruction |
results = classify(instruction, results[0], results[1])
results
end
@jsn = export(@users)
puts @jsn
end
FROM alpine:3.5
ENV BUILD_PACKAGES bash curl-dev ruby-dev build-base git libstdc++ tzdata ca-certificates
ENV RUBY_PACKAGES ruby>2.3 ruby-irb ruby-rake ruby-io-console ruby-bigdecimal ruby-json
RUN apk update && apk upgrade
RUN apk add $BUILD_PACKAGES && apk add $RUBY_PACKAGES
RUN apk add ruby-bundler>1.17
RUN echo 'gem: --no-document' > /etc/gemrc && rm -rf /var/cach/apk/*
RUN gem install bundler
RUN mkdir /usr/app
WORKDIR /usr/app
RUN git init
COPY . /usr/app
RUN bundle install
RUN bundle exec rake install
EXPOSE 4567
CMD ["ruby", "./app.rb"]
ruby app.rb
或
bundle exec rerun app.rb
命令在docker外部运行,它将正常运行。但是使用docker image却没有。我运行命令:
docker run -p 4567:4567 eivor/ruby
[2019-03-14 16:59:59] INFO WEBrick 1.3.1
[2019-03-14 16:59:59] INFO ruby 2.3.8 (2018-10-18) [x86_64-linux-musl]
== Sinatra (v2.0.5) has taken the stage on 4567 for development with backup from WEBrick
[2019-03-14 16:59:59] INFO WEBrick::HTTPServer#start: pid=1 port=4567
connection reset by peer
。如果我尝试使用curl进行发布,则实际上发送了数据,但它没有响应,而是挂断了我。
curl -v localhost:4567 --data-binary @test/input
* Rebuilt URL to: localhost:4567/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 4567 (#0)
> POST / HTTP/1.1
> Host: localhost:4567
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Length: 369
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 369 out of 369 bytes
* Recv failure: Connection reset by peer
* stopped the pause stream!
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
最佳答案
发生此问题的原因是默认情况下(开发环境)Sinatra侦听127.0.0.1,在外部连接到容器的情况下,此侦听器不起作用
:bind - server hostname or IP address
String specifying the hostname or IP address of the interface to listen on when the :run setting is enabled. The default value in the development environment is 'localhost' which means the server is only available from the local machine. In other environments the default is '0.0.0.0', which causes the server to listen on all available interfaces.
docker run -p 4567:4567 --name stack eivor/ruby bash -c 'ruby ./app.rb -o 0.0.0.0'
可以在Dockerfile中用作:
CMD ["ruby", "./app.rb", "-o", "0.0.0.0"]
或者,您可以在脚本中使用以下命令:
set :bind, '0.0.0.0'
然后从容器外部可以得到结果:
curl -v localhost:4567
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 4567 (#0)
> GET / HTTP/1.1
> Host: localhost:4567
> User-Agent: curl/7.64.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html;charset=utf-8
< Content-Length: 13
< X-Xss-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Server: WEBrick/1.3.1 (Ruby/2.3.8/2018-10-18)
< Date: Thu, 14 Mar 2019 17:17:20 GMT
< Connection: Keep-Alive
<
* Connection #0 to host localhost left intact
hello, world!
有关更多配置,请检查以下内容:
CONFIGURING SETTINGS
关于ruby - 将Webservice打包到Docker镜像后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55144337/
WebService 依赖: org.springframework.boot spring-boot-starter-web-services org.apache.cxf cxf-rt-fr
我需要在我的项目中使用 Web 服务。我使用 NetBeans,因此右键单击我的项目并尝试添加新的“Web 服务客户端”。上次我检查过,这是创建 Web 服务客户端的方法。但它导致了一个断言错误,说:
我在 Netbeans 中创建了两个 Java SOAP Web 服务。基本上每个服务都是一个不同的 Web 应用程序,有自己的 war 文件。我从 Java 客户端调用第一个 WS,并从第一个服务调
有没有一种有效的工具可以将 .Net C# webservice 转换为 java webservice。是否有任何开源工具可以提供帮助? 最佳答案 不要浪费时间寻找过渡工具。如果您使用的是 Java
情况是这样的。我从某人那里收到了由 Apache/Tomcat 服务器 (Java) 生成的 WSDL(包括 XSD)。我为其做一个项目的公司更喜欢 .NET,因此我使用 wsdl.exe 生成部分类
我正在使用 java 开发 axis2 网络服务,用于将记录插入数据库。我正在测试 web 服务客户端,它返回空响应代码,实际上我在 web 服务中返回整数值但我成功地将记录插入数据库,我可以在执行客
您好,我正在尝试使用 json 在钛中调用 webService。该 webService 不接受任何参数,所以我只需要调用它。 这是我的代码: var xhr = Titanium.Network.
我正在尝试将基本的Web服务模板部署到tomee,我尝试了Windows 7 64位和Windows 8 64位以及java版本1.8.0_25(64位),1.8.0_91(64位)(此java版本用
我正在尝试使用包含 web 服务参数的 get 方法调用 web 服务。但我无法在互联网上找到答案,请任何人帮助我。下面给出我的网络服务 http://api.crmseries.com/user/V
调用 Web 服务时出现以下抛出错误。除了人们问同样的问题外,用谷歌搜索没有任何结果。 Server was unable to process request. ---> The surrogate
我正在尝试使用 Yahoo 查询语言找到一种通过 Yahoo Weather 获取一些天气信息的方法。 因为我住在法国的一个叫尼斯的城市,下面的查询返回一个错误: select * from weat
我需要知道是否可以从后台调用 json webservices,当用户按下主页按钮时,我从后台执行调用此方法 - (void) runTimer { [NSThread detachNewTh
我有一个 Web 服务,它位于这样的反向代理后面: 现在发生的情况是,当我尝试添加 Web 引用来测试 Web 服务时,它说无法下载 wsdl 文件。那是因为当请求被发送时它是 https://uat
我需要创建一个Web服务,该服务用于通过输入一个字符串ID从服务器下载音频(wav)文件。如果服务器上不存在音频文件,则需要以json格式发送错误回传。 现在的问题是-如何为下载文件提供扩展名。我不知
我编写了一个 C# WebService。问题是,在我将其发布到 IIS 后,除非调用其任何方法,否则它不会自动启动。这是非常令人沮丧的,因为这个 WebService 必须在启动(其构造函数执行)后
simple spring example demoServiceImpl org.apache.axis2.extensions.spring.
我使用 reSTLet 为我的应用程序构建了 Java Web 服务。它是纯 Java 且独立的。有没有免费的云服务可以托管我的网络服务? 它的要求确实很低。其中之一是静态 IP。 最佳答案 使用 j
我正在研究基于 SOAP 的 Web 服务。我需要测试一个场景,如果由于任何网络问题或登录问题而发生 Web 服务连接错误。 apache cxf 的问题是无论 web 服务抛出什么异常 "java
如何在没有datamapper的情况下在mule中调用soap webservice并且输入是xml。我正在使用社区添加。 & 我的输入是 xml 而不是肥皂信封。 我的 wsdl 位置是 - htt
我知道 php webservice SOAP、json、rest 等,但我是 java webservice 的新手。现在我想让 php 客户端连接到 java webservice。最好的方法是什
我是一名优秀的程序员,十分优秀!