Running Python on Docker Container

Hi Not really a Wappler Specific question so I think I have chose the right Category but please feel free to move if I haven’t and since we have a very well informed community here. I was wondering how would I run some code inside and on some of the DB and Files contained in my Node JS docker.

Just learning the ropes of Docker (very comfortable with VPS and Command Line) but I can’t quite get my head around how this would work. Maybe an example of what I am trying to achieve would make this easier to explain.

Say I wanted to use Wappler as the front end and DB and for most of the server side code. What I want to do is upload a file keep track of where that file is in the DB. Once I have uploaded that file I want to have a Python Script checking the DB and then to run some functions on that File. Once I have done that I am going to put an entry into the DB (via the Pythong Script). I will then report back through Wappler that the file is now ready and can be downloaded. I know I would be fine in Wappler watching for the new DB entry etc (may even look into sockets function for that). What I am not sure on is how can I access the docker container to access the DB and run my Python script etc. Any pointers would be great or if I am not being clear please let me know!

Thanks

Containers are isolated from the world by default. But obviously for them to speak to the outer world you need to open a communication line.

Enter docker networking:

You will create a docker virtual network and forward some ports depending on your needs.

It’s not much different from opening a port on a Ubuntu server.

If you need to run a python script that monitors a postgresql instance running in your container you will just need to reach your database on the port you forwarded from the container to your machine.

Check this pg database I have running on my laptop:

Standard PG port is forwarded to 9906 so I can reach my pg instance via localhost:9906

And check this network where it’s running:

That’s how each container can speak to each other as they belong to the same network. You can also have different networks being able to communicate between each one. All explained in the link I left you up there.

1 Like

Thanks Jon, I’ll take a look through!