简体   繁体   English

如何使用带有 VS Code 的活动容器在 Docker 上运行 python 程序?

[英]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来构建wordpressmysql ,而wordpress基于mysql ,而mysqldocker-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 -dwordpress连接到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.

相关问题 无法在VS Code中运行Python程序-无法将“ cmd”识别为 - Can't run Python programs in VS Code - 'cmd' is not recognized as an VS Code 无法定位 python 可执行文件并通过运行按钮运行程序 - VS Code can't locate python executable and run programs through run button 如何配置 Geany 来编译和运行我的 Python 程序? - How can I configure Geany to compile and run my Python programs? 我可以使用Python运行其他程序吗? - Can I run other programs with Python? 运行Docker容器的Python脚本 - Python script to run docker containers python docker sdk 如何在containers.run 中运行多个命令 - python docker sdk how to run multiple commands in containers.run 如何为 3 个容器使用单端口而不是 3 个端口 Python-Flask、PostgreSQL 和 Angular8? 所以我可以使用 Docker 运行而不是 Docker 撰写 - How to use Single port for 3 containers instead of 3 ports Python-Flask, PostgreSQL & Angular8 ? so I can use Docker Run instead of Docker Compose 如何在后台运行 Python Docker 容器并在我的命令中使用它们? - How do I run Python Docker containers in the background and use them in my commands? 如何在VS Code和Ubuntu中使用Keras模块运行python代码? - How can I run a python code with Keras module in VS Code and Ubuntu? Python docker sdk 如何在containers.run中设置cpu计数 - Python docker sdk how to set cpu count in containers.run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM