简体   繁体   English

在 uWSGI 实例中从烧瓶请求创建 docker 容器

[英]Create docker container from flask request in uWSGI instance

I have a docker container that is setup to perform some given actions with selenium.我有一个 docker 容器,它被设置为使用 selenium 执行一些给定的操作。 My goal is to have the docker container be created when a request is received for a certain endpoint created using flask.我的目标是在收到对使用烧瓶创建的某个端点的请求时创建 docker 容器。 The flask app has been setup with uWSGI and Nginx using this tut .已经使用这个tut使用 uWSGI 和 Nginx 设置了 Flask 应用程序。

When the endpoint receives a request it is suppose to run the bash script ./run.sh:当端点收到请求时,它应该运行 bash 脚本 ./run.sh:

#!/bin/bash

ID=$1

docker run --rm \
        -v $(pwd)/code:/code \
        -v /etc/hosts:/etc/hosts \
        selenium \
        python3 \
        /code/main.py ${ID}

I can successfully make a call to the endpoint using the IP given from digital ocean but when it gets to the point where it needs to run docker it says:我可以使用从数字海洋提供的 IP 成功调用端点,但是当它到达需要运行 docker 的地步时,它说:

docker: command not found泊坞窗:找不到命令

Note, I can go into the virtualenv manually, run python app.py, send request to flask endpoint and the docker container is created and everything works great.请注意,我可以手动进入 virtualenv,运行 python app.py,向flask 端点发送请求,然后创建 docker 容器,一切正常。

You probably need to add a PATH variable to your bash script which includes the location of your docker executable.您可能需要在 bash 脚本中添加一个 PATH 变量,其中包括 docker 可执行文件的位置。 The user running NGINX likely doesn't have a path set.运行 NGINX 的用户可能没有设置路径。

PATH=$PATH:/usr/local/bin:/usr/bin

Also you'll need to ensure that the user running NGINX has permission to use docker, so add them to the docker group.此外,您还需要确保运行 NGINX 的用户有权使用 docker,因此将它们添加到 docker 组。

If this is a public service, then I would think carefully about whether you really want internet users to be launching containers on your server, does $1 come from user input?如果这是一项公共服务,那么我会仔细考虑您是否真的希望互联网用户在您的服务器上启动容器,$1 是否来自用户输入?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM