Reputation: 5468
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?
Upvotes: 0
Views: 1702
Reputation: 17443
You can submit the script inline using the -c
option of the Python interpreter:
docker run --rm python:2 python -c 'print "Hello Python"'
Upvotes: 2