微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

amazon-web-services – 如何使用Elastic beanstalk和Dockerrun.aws.json正确部署到AWS?

我目前有一个本地工作的docker镜像,并在hub.docker.com上私下托管.

在容器内我有导轨,美洲狮,Nginx. Elastic beanstalk能够从docker hub成功提取映像,但之后无法执行任何操作.

AWS有Nginx并且正在返回此错误.有谁能够指出我做错了什么?

AWS错误日志

-------------------------------------
/var/log/Nginx/error.log
-------------------------------------
2014/12/27 08:48:34 [emerg] 3161#0: no host in upstream ":80" in           /etc/Nginx/conf.d/elasticbeanstalk-Nginx-docker-upstream.conf:2

更多AWS错误日志

Nginx: [emerg] no host in upstream ":80" in /etc/Nginx/conf.d/elasticbeanstalk-Nginx-    docker-upstream.conf:2
Nginx: con@R_404_6408@uration file /etc/Nginx/Nginx.conf test Failed
Failed to start Nginx, abort deployment (Executor::NonZeroExitStatus)
    at /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/executor-1.0/lib/executor/exec.rb:81:in `sh'
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/executor-1.0/lib/executor.rb:15:in `sh'
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/executable.rb:63:in `execute!'
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/hook-directory-executor.rb:29:in `block (2 levels) in run!'
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `call'
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `exec'
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec'
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:110:in `block

src文件错误

upstream docker {
        server :80;
        keepalive 256;
}

这是我的文件.

Dockerfile

FROM ruby:2.1.5

#################################
# native libs
#################################

RUN apt-get update -qq
RUN apt-get install -qq -y build-essential
RUN apt-get install -qq -y libpq-dev
RUN apt-get install -qq -y nodejs
RUN apt-get install -qq -y npm
RUN apt-get install -qq -y Nginx

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

#################################
# Install Nginx.
#################################

RUN echo "\ndaemon off;" >> /etc/Nginx/Nginx.conf
RUN chown -R www-data:www-data /var/lib/Nginx
ADD con@R_404_6408@/Nginx.conf /etc/Nginx/sites-enabled/default

EXPOSE 80

#################################
# Symlinking Nodejs for ubuntu
#   -- https://stackoverflow.com/questions/26320901/cannot-install-nodejs-usr-bin-env-node-no-such-file-or-directory
#################################
RUN ln -s /usr/bin/nodejs /usr/bin/node

#################################
# NPM install globals
#################################

RUN npm install bower -g

#################################
# Rails
#################################

RUN mkdir /app
workdir /app
ADD . /app

ENV RAILS_ENV production
ENV SECRET_KEY_BASE test123

RUN bundle install --without development test
RUN bundle exec rake bower:install
RUN bundle exec rake assets:precompile

CMD foreman start -f procfile

Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": "1",
  "Authentication": {
    "Bucket": "aws-bucket",
    "Key": ".dockercfg"
  },
  "Image": {
    "Name": "ericraio/my-image",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": "80"
    }
  ],
  "Logging": "/var/log/Nginx"
}

Nginx

upstream rails_app {
  server unix:///app/tmp/sockets/puma.sock fail_timeout=0;
}

server {
  # listen 80 deferred;
  # server_name domain.tld www.domain.tld;
  root /app/public;

  try_files $uri/index.html $uri @rails_app;

  location @rails_app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://rails_app;
  }

  error_page 500 504 /500.html;
  error_page 502 /502.html;
  error_page 503 /503.html;

  client_max_body_size 4G;
  keepalive_timeout 10;
}

解决方法:

问题是在EC2上容器无法运行. Amazon使用此命令构建IP地址并设置环境变量.

EB_CON@R_404_6408@_Nginx_UPSTREAM_IP=$(docker inspect `cat $EB_CON@R_404_6408@_DOCKER_STAGING_APP_FILE` | jq -r .[0].NetworkSettings.IPAddress)

然后亚马逊使用此行来构建IP地址.

EB_CON@R_404_6408@_Nginx_UPSTREAM_PORT=`cat $EB_CON@R_404_6408@_DOCKER_STAGING_PORT_FILE`

我暴露了我的端口80,但因为我的容器无法运行我没有主机.这就是你得到这个错误的原因.

上游没有主机“:80”

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐