如何将我的Python Flask应用Docker化,并使其与Cassandra和Kafka容器一起运行?

huangapple go评论125阅读模式
英文:

Docker- How can I dockerize my Python Flask app and make it run with Cassandra and Kafka Containers?

问题

我的Flask应用目前无法在Docker上运行,我是从一个集成开发环境(IDE)中运行它的。我的应用包括4个文件,分别是app.py(https://pastebin.pl/view/e9590e45)、main.py(https://pastebin.pl/view/5896caaf)、esp32_simulator.py(https://pastebin.pl/view/c5428a6d)和SensorData.py(https://pastebin.pl/view/440b69f4)。我的Cassandra数据库在Docker容器中运行,它位于与其他组件隔离的网络中。我还有一个Kafka堆栈的Docker Compose文件(我从confluentinc/kafka-images获取的),其中包含2个容器,分别命名为kafka1和zoo1,运行在名为kafka-stack-docker-compose的堆栈中。我需要找到一种方法,将我的Python Flask应用程序添加到Docker容器中运行,并且需要找到一种方法让这3个组件(Flask、Cassandra、Kafka)连接并协同工作,以便我可以与我的上级共享这些Docker容器,让他能在自己的计算机上运行它。

我尝试过设置一个新的网络并将它们都运行在同一个网络上,但我目前在我的Cassandra数据库(包括表和数据等)和Kafka(包括keyspaces)中有太多的数据,所以我不敢删除它们并重新配置。

英文:

My flask app is not running on docker currently I am running it from an IDE. And it has 4 files named app.py(https://pastebin.pl/view/e9590e45), main.py(https://pastebin.pl/view/5896caaf), esp32_simulator.py(https://pastebin.pl/view/c5428a6d) and SensorData.py(https://pastebin.pl/view/440b69f4). My cassandra is running on docker on a separate network from other things. I have a kafka-stack-docker-compose(which I pulled from confluentinc/kafka-images) which has 2 containers named kafka1, zoo1 running inside a stack named kafka-stack-docker-compose. I need to somehow add my python flask application to run on docker and then I need to somehow make these 3(flask, cassandra, kafka) connect and work together so I can share this docker containers with my supervisor for him to run it on his own computer.

I tried setting up a new network and running it all on the same but I currently have too much data both on my cassandra(table's and such) and my kafka(keyspaces) so I am afraid to delete them and configure them again.

答案1

得分: 1

  • "How can I dockerize my Flask App" -> "如何将我的Flask应用程序Docker化"
  • "The Docker blog seems to cover this on its own." -> "Docker博客似乎已经独自涵盖了这个问题。"
  • "need to somehow make these 3(flask, cassandra, kafka) connect and work together" -> "需要以某种方式使这三个(Flask、Cassandra、Kafka)连接并一起工作"
  • "You would do this in one Compose file, and therefore one network, by default." -> "您将在一个Compose文件中完成此操作,默认情况下将使用一个网络。"
  • "I suggest referring the Docker Compose documentation on how containers would be networked together." -> "我建议查阅Docker Compose文档,了解如何将容器连接在一起。"
  • "Then Kafka has specific environment variables to configure, but Cassandra should work the same as any other external service." -> "然后,Kafka有特定的环境变量需要配置,但Cassandra应该与其他外部服务一样工作。"
  • "share this docker containers with my supervisor for him to run it on his own computer." -> "与我的主管分享这些Docker容器,以便他在自己的计算机上运行它。"
  • "You can push your Docker image to DockerHub, or a private Docker Registry in your company, if one is available." -> "您可以将Docker镜像推送到DockerHub,或者如果公司内有私有Docker注册表的话,也可以将其推送到私有Docker注册表。"
  • "Otherwise, you need to share your source code, Dockerfile and docker-compose file, then require your supervisor to have Docker installed as well..." -> "否则,您需要分享您的源代码、Dockerfile docker-compose文件,然后要求您的主管也安装Docker..."
  • "IMO, it would be easier to run your Flask app somewhere else like Google Cloud Run, then provide an accessible HTTP URL and hide away the backend services." -> "在我看来,将您的Flask应用程序在其他地方运行,如Google Cloud Run,然后提供可访问的HTTP URL并隐藏后端服务会更容易。"
英文:

> How can I dockerize my Flask App

The Docker blog seems to cover this on its own.

> need to somehow make these 3(flask, cassandra, kafka) connect and work together

You would do this in one Compose file, and therefore one network, by default.

I suggest referring the Docker Compose documentation on how containers would be networked together. Then Kafka has specific environment variables to configure, but Cassandra should work the same as any other external service.

> share this docker containers with my supervisor for him to run it on his own computer.

You can push your Docker image to DockerHub, or a private Docker Registry in your company, if one is available. Otherwise, you need to share your source code, Dockerfile and docker-compose file, then require your supervisor to have Docker installed as well... IMO, it would be easier to run your Flask app somewhere else like Google Cloud Run, then provide an accessible HTTP URL and hide away the backend services.

huangapple
  • 本文由 发表于 2023年6月15日 19:39:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76482099.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定