简体   繁体   English

使用不同的机器(本地网络)从 Docker 容器外部访问 KSQL Server

[英]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 容器来运行zookeeperkafkaksqlksql-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-serverksql-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.

相关问题 如何从其他机器访问服务器(在docker容器中运行)? - How to access a server(which is running in a docker container) from other machine? Docker 容器无法访问本地网络设备 - Docker Container cannot access local network devices 从 docker 容器读取本地机器上的文件 - Reading files on local machine from docker container Docker容器在服务器上的行为与本地机器不同 - uwsgi和nginx - Docker container has different behaviour on server than local machine - uwsgi and nginx 如何从同一 local.network 上的不同机器/IP 访问 FastAPI 后端? - How to access FastAPI backend from a different machine/IP on the same local network? 无法从 Docker 容器访问本地主机 - Unable to Access Local Host From Docker Container 如何使用 node/python 从本地网络外部访问 Hue Lights? - How do I access Hue Lights from outside the local network using node/python? 从容器(docker)访问服务器资源 - Access server ressource from the container (docker) 从主机访问 mariadb docker-compose 容器 - Access mariadb docker-compose container from host-machine Docker-compose:如何使用相同的网络地址从容器和主机访问 Localstack 资源 - Docker-compose: How to access Localstack resources both from container and host, using same network address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM