简体   繁体   中英

Running a docker container to execute python script with minimal footprint

I have a node.js server that gets an python script as an input from the web client (Yes, risky), the server runs the script and return the output to the client.

In order to minimize the risks here, I'm creating a docker container for the execution of the script with the following command:

docker run -it --rm --name python-script-instance -v /dir/on/server:/tmp python:2 python /tmp/script.py

It requires creating a directory on the server that will hold a file named script.py , the host server directory is mounted to /tmp on the container and allow access to script.py through /tmp/script.py

I dont wan't to have script.py created on the server, I want to dynamically take it from memory directly into the docker container.

I thought about passing the entire script as a command line argument to the python interpreter, but was unsuccessful to get it to work.

Any suggestions on how can I execute a python script encapsulated in a docker container leaving a minimal footprint on the host server?

您可以使用Python解释器的-c选项内联提交脚本:

docker run --rm python:2 python -c 'print "Hello Python"'

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