简体   繁体   English

如何为在 docker 容器内运行的快速服务器启用 xvfb?

[英]How to enable xvfb for an express server running inside a docker container?

I have a express server running inside a docker container.我有一个在 docker 容器内运行的快速服务器。 Once a user makes a REST call to an endpoint, it should make multiple in-memory screenshots of a randomly generated mesh from different angles using Babylon.js, do some image processing on it, create a PDF out of it and return the generated PDF file to the user.一旦用户对端点进行 REST 调用,它应该使用 Babylon.js 从不同角度对随机生成的网格进行多个内存截图,对其进行一些图像处理,从中创建 PDF 并返回生成的 PDF 并返回生成的 ZBCD1B68617DFC0403文件给用户。

To do so, I am trying to use headless-gl to provide virtual frame buffer for Babylon.js engine.为此,我尝试使用headless-gl为 Babylon.js 引擎提供虚拟帧缓冲区。

As far as I understood, I first need to get the gl context and then pass it to babylon engine:据我了解,我首先需要获取 gl 上下文,然后将其传递给巴比伦引擎:

var gl = require(‘gl’)(1024, 768, { preserveDrawingBuffer: true });

var engine = new BABYLON.Engine(gl, true, { disableWebGL2Support: true });

My issue is that I am not able to init the gl and it returns null .我的问题是我无法初始化 gl 并且它返回null

Inside my Dockerfile, I use the following to install the dependencies for xvfb :在我的 Dockerfile 中,我使用以下内容安装xvfb的依赖项:

RUN apt-get update && apt-get install -y
libgl1-mesa-dri
libglapi-mesa
libosmesa6
mesa-utils
xvfb
&& apt-get clean

My server depends on mongo DB as well so inside my docker-compose.yml file, I wait for the DB container to get initialized before I load my express container:我的服务器也依赖于 mongo DB,因此在我的 docker-compose.yml 文件中,我等待 DB 容器初始化,然后再加载我的 express 容器:

command: wait-for.sh mongodb:27017 – …/node_modules/.bin/nodemon --inspect=0.0.0.0:9229 ./server.js

I think I need to updated my Dockerfile and docker-compose files with proper commands to load xvfb before running the node application but I am not sure how to do that.我想我需要使用正确的命令更新我的 Dockerfile 和 docker-compose 文件,以在运行节点应用程序之前加载xvfb ,但我不知道该怎么做。

I tried the following along with some other combinations but no luck so far:我尝试了以下以及其他一些组合,但到目前为止没有运气:

command: wait-for.sh mongodb:27017 – xvfb-run -s “-ac -screen 0 1280x1024x24” node ./server.js

I appreciate if someone can help me resolve the issue.如果有人可以帮助我解决问题,我将不胜感激。

I think you are missing the server number as an argument.我认为您缺少服务器编号作为参数。 I am using xvfb-run --auto-servernum <command> to automatically get a free one.我正在使用xvfb-run --auto-servernum <command>来自动获得一个免费的。 The default is number 99.默认值为 99。

You can also use Xvfb manually with the DISPLAY environment variable set to :99 (default server number), but xvfb-run makes live a lot easier.您也可以手动使用 Xvfb,并将 DISPLAY 环境变量设置为:99 (默认服务器编号),但 xvfb-run 使直播变得更容易。 I think you already read this, but for future users I will quote the stackgl/headless-gl README:我想你已经阅读了这篇文章,但对于未来的用户,我将引用stackgl/headless-gl README:

Interacting with Xvfb requires you to start it on the background and to execute your node program with the DISPLAY environment variable set to whatever was configured when running Xvfb (the default being:99).与 Xvfb 交互需要您在后台启动它并执行节点程序,并将 DISPLAY 环境变量设置为运行 Xvfb 时配置的任何内容(默认值为:99)。 If you want to do that reliably you'll have to start Xvfb from an init.d script at boot time, which is extra configuration burden.如果你想可靠地做到这一点,你必须在启动时从 init.d 脚本启动 Xvfb,这是额外的配置负担。 Fortunately there is a wrapper script shipped with Xvfb known as xvfb-run which can start Xvfb on the fly, execute your Node.js program and finally shut Xvfb down.幸运的是,Xvfb 附带了一个称为 xvfb-run 的包装脚本,它可以即时启动 Xvfb,执行 Node.js 程序,最后关闭 Xvfb。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 AWS SAM 本地 Docker 容器访问另一个 Docker 容器(运行节点快速服务器)? - How do I access another Docker container (running a node express server) from a AWS SAM Local Docker container? 如何设置 docker-compose.yml、Express 和 TypeORM 以将我的 Express 服务器连接到容器内的 Postgres 数据库? - How do I set up docker-compose.yml, Express and TypeORM to connect my Express server to a Postgres db inside the container? 在另一个Docker容器中运行一个Docker容器? - Running a docker container inside another docker container? 有条件地检测节点服务器是否在 Docker 容器内运行 - Conditionally detecting whether a Node server is running inside a Docker Container Docker - 如何查看 Docker 容器内运行应用程序的日志? - Docker - How to see the logs of running application inside Docker container? ECONNREFUSED nodeJS 与 docker 容器内的 express - ECONNREFUSED nodeJS with express inside docker container Swagger Express在Docker容器内给出错误 - Swagger express gives error inside docker container 如何调试运行在docker容器内的节点程序 - how to debug node program running inside docker container 如何将Vue客户端代理到在docker容器中运行的Express服务器 - How to proxy Vue client to Express server running in docker containers 从另一个docker容器内部访问在docker容器中运行的服务 - Access service running in docker container from inside another docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM