[英]Access KSQL Server from outside of a Docker Container using a different machine (local network)
I have created the following Docker containers to run zookeeper
, kafka
, ksql
, and ksql-cli
as well.我创建了以下 Docker 容器来运行zookeeper
、 kafka
、 ksql
和ksql-cli
。 When I am running the command docker-compose exec ksqldb-cli ksql http://ksqldb-server:8088
from the same machine where Docker is running, ksql-cli
can access the ksql-server
just fine.当我从 Docker 运行的同一台机器上运行命令docker-compose exec ksqldb-cli ksql http://ksqldb-server:8088
ksql-server
, ksql-cli
However, I want to have access to the ksql-server
outside of the same machine but using a different laptop under the same local network.但是,我想访问同一台机器之外的ksql-server
,但在同一本地网络下使用不同的笔记本电脑。 How do I do that?我怎么做?
Here's the relevant docker-compose.yml
file:这是相关的docker-compose.yml
文件:
version: '3.8'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
container_name: zookeeper
networks:
- kafka_network
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 22181:2181
kafka:
image: confluentinc/cp-kafka:latest
container_name: kafka
networks:
- kafka_network
depends_on:
- zookeeper
ports:
- 29092:29092
- 29093:29093
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENERS: EXTERNAL_SAME_HOST://:29092,EXTERNAL_DIFFERENT_HOST://:29093,INTERNAL://:9092
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,EXTERNAL_SAME_HOST://localhost:29092,EXTERNAL_DIFFERENT_HOST://192.168.178.218:29093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL_SAME_HOST:PLAINTEXT,EXTERNAL_DIFFERENT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
ksqldb-server:
image: confluentinc/cp-ksqldb-server:latest
container_name: ksqldb-server
hostname: ksqldb-server
networks:
- kafka_network
depends_on:
- kafka
ports:
- "8088:8088"
environment:
KSQL_CONFIG_DIR: "/etc/ksql"
KSQL_BOOTSTRAP_SERVERS: "kafka:9092"
KSQL_HOST_NAME: ksqldb-server
KSQL_LISTENERS: "http://0.0.0.0:8088"
KSQL_CACHE_MAX_BYTES_BUFFERING: 0
KSQL_KSQL_SCHEMA_REGISTRY_URL: "http://schema-registry:8081"
KSQL_KSQL_LOGGING_PROCESSING_TOPIC_REPLICATION_FACTOR: 1
KSQL_KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE: 'true'
KSQL_KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE: 'true'
ksqldb-cli:
image: confluentinc/cp-ksqldb-cli:latest
container_name: ksqldb-cli
networks:
- kafka_network
depends_on:
- kafka
- ksqldb-server
entrypoint: /bin/sh
tty: true
networks:
kafka_network:
name: kafka_docker_sse
When I try accessing the ksql-server
from a different laptop that is under the same local network, I get a connection error/connection refused.当我尝试从同一本地网络下的另一台笔记本电脑访问ksql-server
时,我收到连接错误/连接被拒绝。 I tried accessing the ksqldb-server
using the Python ksql-python package.我尝试使用 Python ksql-python package 访问ksqldb-server
。
pip install ksql
from ksql import KSQLAPI
client = KSQLAPI('http://ksql-server:8088')
# OR
# client = KSQLAPI('http://0.0.0.0:8088')
# client = KSQLAPI('http://192.168.178.218:8088')
if __name__ == '__main__':
print(client)
I also tried changing the KSQL_LISTENERS: "http://0.0.0.0:8088"
under the ksqldb-server
to KSQL_LISTENERS: "http://192.168.178.218:8088"
but that doesn't work either.我还尝试将ksqldb-server
下的KSQL_LISTENERS: "http://0.0.0.0:8088"
更改为KSQL_LISTENERS: "http://192.168.178.218:8088"
但这也不起作用。
Any hints would be really helpful as I am currently stuck here for the last two days!任何提示都会非常有帮助,因为我最近两天都被困在这里!
You'll need to keep KSQL_LISTENERS: "http://0.0.0.0:8088"
.您需要保留KSQL_LISTENERS: "http://0.0.0.0:8088"
。 This binds the container to accept all incoming traffic into port 8088这将容器绑定为接受所有传入端口 8088 的流量
Then, with ports
in Compose, the host 8088 traffic is forwarded to the container 8088.然后,使用 Compose 中的ports
,将主机 8088 流量转发到容器 8088。
So, for any external client, you need to connect to that hosts LAN / external IP on port 8088. You may need to explicitly allow TCP traffic into that server host's firewall for that port.因此,对于任何外部客户端,您需要在端口 8088 上连接到该主机 LAN/外部 IP。您可能需要明确允许 TCP 流量进入该服务器主机的防火墙以用于该端口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.