Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run python script in docker with the script being sent dynamically to docker container?

Tags:

python

docker

How to run python script in docker with the script being sent dynamically to docker container ?

Also, it should handle multiple simultaneous connections. For example, if two run is executed by two people at once, it should not override the file created by one person by the another.

like image 654
user1305989 Avatar asked Oct 02 '16 04:10

user1305989


People also ask

How do I Dockerize a Python program?

Form your new directory by creating a new root project folder in the sidebar, and naming it. Open a new workspace named main.py . Enter the cd [root folder name] command in the Terminal to tap into your new directory. Copy and paste any pre-existing Python application code into your main.py workspace.


1 Answers

Normally, you Mount a host file as a data volume, or, in your case, a host directory.
See the python image:

docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3 python your-daemon-or-script.py

That way, if a file is created in that mounted folder, it will be created on the host hard-drive, and won't be overridden by another user executing the same script in his/her own container.


For an Ubutu image, you need

  • an initial copy of the Git repo, cloned as a bare repo (git clone --mirror).
  • an Apache installed, listening for Git request

When you fetch a PR, you can run a new container, and push that PR branch to the container Git repo. A post-receive hook on that container repo can trigger a python script. - then you can

like image 60
VonC Avatar answered Oct 20 '22 22:10

VonC