简体   繁体   中英

Create docker container from flask request in uWSGI instance

I have a docker container that is setup to perform some given actions with selenium. My goal is to have the docker container be created when a request is received for a certain endpoint created using flask. The flask app has been setup with uWSGI and Nginx using this tut .

When the endpoint receives a request it is suppose to run the bash script ./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:

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.

You probably need to add a PATH variable to your bash script which includes the location of your docker executable. The user running NGINX likely doesn't have a path set.

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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