[英]How Can I Run the python programs on Docker using active containers with the VS Code?
I want to run Kafka producer / consumer and connect them to the Broker using VS Code.我想运行 Kafka 生产者/消费者并使用 VS Code 将它们连接到 Broker。
1- I have already run a Kafka Broker with the docker-compose, with an active Kafka container. 1- 我已经用 docker-compose 运行了一个 Kafka Broker,有一个活动的 Kafka 容器。 How can I use the Kafka container without installing it locally ?如何在不本地安装的情况下使用 Kafka 容器?
I have installed the kafka library on my local machine, and everything worked perfectly..我已经在我的本地机器上安装了 kafka 库,一切正常。
Expected: Using the Kafka container instead of the local lib.预期:使用 Kafka 容器而不是本地库。
I'm answering this with the assumption that when you say you machine, you're referring to your local machine (I would comment directly on your question ask for clarification, but I don't have enough rep yet).我在回答这个假设时假设你说你的机器,你指的是你的本地机器(我会直接对你的问题发表评论,要求澄清,但我还没有足够的代表)。 Installing a library locally allows for it to work locally, but not in other environments.在本地安装库允许它在本地工作,但不能在其他环境中工作。 So you need to install the Kafka library within the environment you're targeting, too.因此,您还需要在目标环境中安装 Kafka 库。
I don't know kafka
, In my experience, I use docker-compose to build the wordpress
and mysql
, which wordpress
is based on mysql
, which is explicitly stated in their docker-compose.yml
. 我不了解kafka
,以我的经验,我使用docker-compose来构建wordpress
和mysql
,而wordpress
基于mysql
,而mysql
在docker-compose.yml
有明确说明。 When I run docker-compose up -d
, the wordpress
is connected to the mysql
container instead of mysql
on my machine. 当我运行docker-compose up -d
, wordpress
连接到mysql
容器而不是我的机器上的mysql
。
How can I use the Kafka container without installing it locally ?如何在不本地安装的情况下使用 Kafka 容器?
Not clear what "it" is... The Docker image?不清楚“它”是什么...... Docker 镜像? That's not how Docker works.这不是 Docker 的工作方式。
You need to
install
pull the Docker image locally in order to use it您需要在本地
安装
pull Docker 镜像才能使用它
I have installed the kafka library on my local machine我已经在本地机器上安装了 kafka 库
I assume that you mean something downloaded from kafka.apache.org?我假设你的意思是从 kafka.apache.org 下载的东西? If that's the case, no, you don't need that for Python如果是这种情况,不,Python 不需要它
You will instead have to pip install some Kafka Python package and write code to communicate to the Kafka container相反,您将不得不 pip 安装一些 Kafka Python 包并编写代码以与 Kafka 容器进行通信
It sounds like you want to connect to a container or a remote machine using VS Code.听起来您想使用 VS Code 连接到容器或远程机器。 Please see the instructions for remote development in VS Code on how to remotely connect to containers or machines via SSH.请参阅VS Code 中的远程开发说明,了解如何通过 SSH 远程连接到容器或机器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.