IOTstack icon indicating copy to clipboard operation
IOTstack copied to clipboard

Python container?

Open stevenveenma opened this issue 5 years ago • 4 comments

Thanks for your excellent work, this saves me much time! I plan to convert my current setup to your containerized approach, but I am unsure how to deal with Python. I use Python3 to read MQTT, do some cleaning of the data and then store the result in Influxdb. I am expecting to do more with Python in future (prescriptive analytics). I am unsure if I should make an additional container for Python or just use the build in Python and connect to each container manually. What's your advice on this?

stevenveenma avatar Nov 18 '19 10:11 stevenveenma

Hi Steven, running a containerized python script is reasonably straight forward. And it simplifies running a python script as a service.

For the testing and development phase adding it to docker-compose may not be the best route, it involves repeated starting,stopping, deleting and rebuilding.

For established "dockerfied" python code docker-compose offers the convenience of the 'simple' stop and start.

I would recommend you start with the instructions on Python's docker hub and do the Dockerfile route where you build and run your images manually.

What I will do in the mean time is start a wiki entry with instructions on how to do the 'manual method'. I'll also add a python container with instructions on how to use it.

gcgarner avatar Nov 18 '19 11:11 gcgarner

Hi Graham, thanks for your suggestions and plans. I succeeded in making a dockerfile and runned this: docker build -t "python3:Dockerfile" I identify a new Python image in Portainer. But when I do : docker run python3 I get: Unable to find image 'python3:latest' locally

How do I make use of this image now? Besides I use Thonny as EDI. I can select interpreters in Thonny, but can't find the Docker image.

stevenveenma avatar Nov 18 '19 18:11 stevenveenma

I made a very quick demo for you here https://github.com/gcgarner/python_docker_demo (its late here, i can give you more details in the morning)

you can clone it and work from it if you like otherwise you can just use it for inspiration

The instructions are in the README. I think your syntax was wrong

Every time you change the requirements.txt or the source files you will need to build the image again. There is away around this but i can explain that when i have more time

gcgarner avatar Nov 18 '19 20:11 gcgarner

Thanks for you effort on the demo. For final and complete Python programs the container probably is a good solution. But for development I found there is not any problem to use the build in Python and interact with the other docker containers like Mosquitto and Influxdb. Using an EDI, updating libraries and debugging are easy this way.

stevenveenma avatar Nov 19 '19 19:11 stevenveenma