与Docker的弹性豆串的WebSockets [英] WebSockets on Elastic Beanstalk with Docker

查看:150
本文介绍了与Docker的弹性豆串的WebSockets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在现在在单个实例上运行的AWS Elastic Beanstalk中部署Docker映像。除了我通过Socket.IO使用的WebSockets,它一切正常。



另一个帖子建议删除nginx,但这是不可能的,或者只是不是与Docker部署的选项。



我有一个python脚本, nginx配置允许WebSocket连接。当我进入实例并运行该脚本时,它可以工作。但是,当运行ebextensions时,nginx配置的那部分不存在,所以我无法自动运行这个脚本。



如果你想自己尝试,我尝试部署 databench_examples 。当您使用 eb init eb start 然后将ssh添加到实例中并转到 / var / app / current 并运行 sudo python nginx_socketio_conf.py ,它会更改nginx配置文件。如果不起作用,则在运行 simplepi 分析时,在浏览器控制台中会出现一个500错误的Socket.IO握手。

解决方案

正确的是,当运行ebextensions时,nginx配置文件不存在。这就是为什么:配置文件在应用程序部署之后动态生成,因为在容器停止之后,Docker容器的端口映射是不知道的。所以你由ebextensions执行的令人敬畏的Python脚本没有配置文件来操作。



另一个传统的方法不起作用,即将nginx配置文件写入/etc/nginx/conf.d,因为位置指令必须存在于服务器块中$ c> sites_enabled config。所以这是一个没有去的。



我创建了一个PR来说明一个可以工作的方法: https://github.com/svenkreiss/databench_examples/pull/3 这是一个未记录的技术,将Python / nginx变体脚本放在Elastic Beanstalk的hooks目录中的正确位置。然后在生成nginx配置后立即由Elastic Beanstalk执行脚本(Elastic Beanstalk将按照字母顺序在钩子目录中运行可执行脚本,因此 01 _ 前缀。感谢,



Evan


Trying to deploy a Docker image in AWS Elastic Beanstalk running on a single instance for now. It all works fine, apart from WebSockets which I am using through Socket.IO.

Another post suggests to remove nginx, but that is either not possible anymore or just not an option for deployments with Docker.

I have a python script that changes the nginx configuration to allow WebSocket connections. When I ssh into the instance and run that script, it works. However, that part of the nginx configuration does not exist yet when ebextensions are run, so I cannot run this script automatically.

If you want to try it yourself, I am trying to deploy databench_examples. It is working when you deploy this with eb init and eb start and then ssh into the instance and go to /var/app/current and run sudo python nginx_socketio_conf.py which changes the nginx configuration file. If it is not working, you see a 500 error in the browser console for the Socket.IO handshake when running the simplepi analysis.

解决方案

You're correct that the nginx configuration file does not exist when ebextensions are run. Here's why: that config file is dynamically generated after the application is deployed because the port mapping for the Docker container isn't known until after the container stops. So your awesome Python script executed by ebextensions doesn't have a config file to operate on.

Another conventional approach doesn't work, i.e., writing the nginx config file to /etc/nginx/conf.d because the location directive has to exist inside the server block in the sites_enabled config. So that's a no go.

I created a PR to illustrate an approach that will work: https://github.com/svenkreiss/databench_examples/pull/3 This is an undocumented technique that drops the Python/nginx mutation script into the right place in Elastic Beanstalk's hooks directory. The script is then executed by Elastic Beanstalk immediately after the nginx configuration is generated (Elastic Beanstalk will run executable scripts in the hooks subdirectories in alphabetical order, hence the 01_ prefix.

Thanks,

Evan

这篇关于与Docker的弹性豆串的WebSockets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆