2014-07-11 57 views
2

我已經構建了一個簡單的sinatra應用程序,用於偵聽本地主機上的POST請求(包含來自AWS SQS的消息)並配置了dockerfile以便輕鬆部署。使用docker和SQS的AWS Beanstalk上的Sinatra應用程序

西納特拉:

set :environment, 'staging' 
set :bind, 'localhost' 
set :port, '80' 

before do 
    request.body.rewind 
    @request_payload = JSON.parse request.body.read 
end 

post '/' do 
    # do stuff with payload 
end 

Dockerfile:

#https://dockerfile.github.io/#/ruby 
FROM dockerfile/ruby 

# Install dependencies 
RUN apt-get update 
RUN apt-get install postgresql-common postgresql-9.3 libpq-dev -y 

# Copy the Gemfile and Gemfile.lock into the image to cache bundle install 
# Temporarily set the working directory to where they are 
WORKDIR /tmp 
ADD ./Gemfile Gemfile 
ADD ./Gemfile.lock Gemfile.lock 
RUN bundle install 

# Copy code into the image 
ADD . /code 
WORKDIR /code 

# Open port 80 
EXPOSE 80 

# Clean up 
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 

# Default runtime command 
CMD /code/launcher.rb 

但我得到的日誌文件這些錯誤:

------------------------------------- 
/var/log/nginx/error.log 
------------------------------------- 
2014/07/11 20:54:33 [error] 9023#0: *11 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: , request: "POST/HTTP/1.1", upstream: "http://127.0.0.1:12569/", host: "localhost" 

------------------------------------- 
/var/log/docker 
------------------------------------- 
2014/07/11 20:54:33 Can't forward traffic to backend tcp/172.17.0.8:80: dial tcp 172.17.0.8:80: connection refused 

------------------------------------- 
/var/log/aws-sqsd/default.log 
------------------------------------- 
2014-07-11T21:19:35Z http-err: d35bffd4-5c0b-4979-b046-5b42c7a990c0 (6) 502 - 0.023 

------------------------------------- 
/var/log/nginx/access.log 
------------------------------------- 
127.0.0.1 - - [11/Jul/2014:21:19:35 +0000] "POST/HTTP/1.1" 502 172 "-" "aws-sqsd/1.1" 

------------------------------------- 
/var/log/docker-ps.log 
------------------------------------- 
'docker ps' ran at Fri Jul 11 21:11:52 UTC 2014: 
CONTAINER ID  IMAGE        COMMAND    CREATED    STATUS    PORTS      NAMES 
f3d8a8a3ffb6  aws_beanstalk/current-app:latest /bin/sh -c /code/bui About a minute ago Up About a minute 0.0.0.0:12529->80/tcp backstabbing_pare 

任何想法?我認爲它與港口有關。我曾與其他人嘗試過沒有成功......

回答

1

set :bind, 'localhost'指令是衝突。 由於POST請求來自碼頭容器外部,Sinatra拒絕了連接。

相關問題