Unable to access kafka from outside Docker
up vote
0
down vote
favorite
I have a confluent kafka setup and docker-compose.yml file
https://github.com/confluentinc/cp-docker-images/blob/5.0.0-post/examples/kafka-cluster/docker-compose.yml
I have edited the file and added the ports option to the docker compose file so that I can access them outside of the host.
---
version: '2'
services:
zookeeper-1:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 22181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
zookeeper-2:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 2
ZOOKEEPER_CLIENT_PORT: 32181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
zookeeper-3:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 3
ZOOKEEPER_CLIENT_PORT: 42181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
kafka-1:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "19092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:19092
network_mode: "host"
kafka-2:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "29092"
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092
network_mode: "host"
kafka-3:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "39092"
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:39092
network_mode: "host"
I have run the following commands:
docker-compose up --no-start
docker-compose start zookeeper-1
docker-compose start zookeeper-2
docker-compose start zookeeper-3
docker-compose run -d --service-ports kafka-1
docker-compose run -d --service-ports kafka-2
docker-compose run -d --service-ports kafka-3
The zookeeper-1,2,3 started but kafka-1 failed with exit code 0.
When I do docker-compose start kafka-1, the ports are not exposed but the service is started.
The output of the above commands:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7abec60edd7a confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-2_1_c9f58ba3fbc8
68ec403740d6 confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-3_1_31e4762a61bb
69d6645487aa confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-1_1_8bbd729b09d8
docker logs of kafka-1, kafka-2, kafka-3 (all are same)
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/127.0.0.1:42181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/127.0.0.1:42181, initiating session
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:32181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/0:0:0:0:0:0:0:1:32181, initiating session
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:22181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/0:0:0:0:0:0:0:1:22181, initiating session
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main] ERROR io.confluent.admin.utils.ClusterStatus - Timed out waiting for connection to Zookeeper server [localhost:22181,localhost:32181,localhost:42181].
[main] INFO org.apache.zookeeper.ZooKeeper - Session: 0x0 closed
docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------
kafka-cluster_kafka-1_1_c79e5ef5d397 /etc/confluent/docker/run Exit 0
kafka-cluster_kafka-2_1_d4399ed0a670 /etc/confluent/docker/run Exit 0
kafka-cluster_kafka-3_1_2df6f47759c0 /etc/confluent/docker/run Exit 0
kafka-cluster_zookeeper-1_1_8bbd729b09d8 /etc/confluent/docker/run Up
kafka-cluster_zookeeper-2_1_c9f58ba3fbc8 /etc/confluent/docker/run Up
kafka-cluster_zookeeper-3_1_31e4762a61bb /etc/confluent/docker/run Up
docker apache-kafka docker-compose
|
show 6 more comments
up vote
0
down vote
favorite
I have a confluent kafka setup and docker-compose.yml file
https://github.com/confluentinc/cp-docker-images/blob/5.0.0-post/examples/kafka-cluster/docker-compose.yml
I have edited the file and added the ports option to the docker compose file so that I can access them outside of the host.
---
version: '2'
services:
zookeeper-1:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 22181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
zookeeper-2:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 2
ZOOKEEPER_CLIENT_PORT: 32181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
zookeeper-3:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 3
ZOOKEEPER_CLIENT_PORT: 42181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
kafka-1:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "19092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:19092
network_mode: "host"
kafka-2:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "29092"
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092
network_mode: "host"
kafka-3:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "39092"
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:39092
network_mode: "host"
I have run the following commands:
docker-compose up --no-start
docker-compose start zookeeper-1
docker-compose start zookeeper-2
docker-compose start zookeeper-3
docker-compose run -d --service-ports kafka-1
docker-compose run -d --service-ports kafka-2
docker-compose run -d --service-ports kafka-3
The zookeeper-1,2,3 started but kafka-1 failed with exit code 0.
When I do docker-compose start kafka-1, the ports are not exposed but the service is started.
The output of the above commands:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7abec60edd7a confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-2_1_c9f58ba3fbc8
68ec403740d6 confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-3_1_31e4762a61bb
69d6645487aa confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-1_1_8bbd729b09d8
docker logs of kafka-1, kafka-2, kafka-3 (all are same)
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/127.0.0.1:42181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/127.0.0.1:42181, initiating session
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:32181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/0:0:0:0:0:0:0:1:32181, initiating session
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:22181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/0:0:0:0:0:0:0:1:22181, initiating session
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main] ERROR io.confluent.admin.utils.ClusterStatus - Timed out waiting for connection to Zookeeper server [localhost:22181,localhost:32181,localhost:42181].
[main] INFO org.apache.zookeeper.ZooKeeper - Session: 0x0 closed
docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------
kafka-cluster_kafka-1_1_c79e5ef5d397 /etc/confluent/docker/run Exit 0
kafka-cluster_kafka-2_1_d4399ed0a670 /etc/confluent/docker/run Exit 0
kafka-cluster_kafka-3_1_2df6f47759c0 /etc/confluent/docker/run Exit 0
kafka-cluster_zookeeper-1_1_8bbd729b09d8 /etc/confluent/docker/run Up
kafka-cluster_zookeeper-2_1_c9f58ba3fbc8 /etc/confluent/docker/run Up
kafka-cluster_zookeeper-3_1_31e4762a61bb /etc/confluent/docker/run Up
docker apache-kafka docker-compose
what doesdocker pssay?
– freakman
Nov 7 at 8:16
what's the output ofdocker-compose ps? and ofdocker-compose logs kafka-1?
– Robin Moffatt
Nov 7 at 8:26
@freakman I attached the output and logs
– JavaTechnical
Nov 7 at 9:42
1
can you remove the ports and try, since you are already using "host" as the network mode you should be able to access the kafka
– Ntwobike
Nov 7 at 10:21
1
Check out the answer here: stackoverflow.com/questions/51086884/… Might help.
– Bitswazsky
Nov 7 at 12:08
|
show 6 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a confluent kafka setup and docker-compose.yml file
https://github.com/confluentinc/cp-docker-images/blob/5.0.0-post/examples/kafka-cluster/docker-compose.yml
I have edited the file and added the ports option to the docker compose file so that I can access them outside of the host.
---
version: '2'
services:
zookeeper-1:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 22181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
zookeeper-2:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 2
ZOOKEEPER_CLIENT_PORT: 32181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
zookeeper-3:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 3
ZOOKEEPER_CLIENT_PORT: 42181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
kafka-1:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "19092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:19092
network_mode: "host"
kafka-2:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "29092"
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092
network_mode: "host"
kafka-3:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "39092"
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:39092
network_mode: "host"
I have run the following commands:
docker-compose up --no-start
docker-compose start zookeeper-1
docker-compose start zookeeper-2
docker-compose start zookeeper-3
docker-compose run -d --service-ports kafka-1
docker-compose run -d --service-ports kafka-2
docker-compose run -d --service-ports kafka-3
The zookeeper-1,2,3 started but kafka-1 failed with exit code 0.
When I do docker-compose start kafka-1, the ports are not exposed but the service is started.
The output of the above commands:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7abec60edd7a confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-2_1_c9f58ba3fbc8
68ec403740d6 confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-3_1_31e4762a61bb
69d6645487aa confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-1_1_8bbd729b09d8
docker logs of kafka-1, kafka-2, kafka-3 (all are same)
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/127.0.0.1:42181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/127.0.0.1:42181, initiating session
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:32181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/0:0:0:0:0:0:0:1:32181, initiating session
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:22181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/0:0:0:0:0:0:0:1:22181, initiating session
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main] ERROR io.confluent.admin.utils.ClusterStatus - Timed out waiting for connection to Zookeeper server [localhost:22181,localhost:32181,localhost:42181].
[main] INFO org.apache.zookeeper.ZooKeeper - Session: 0x0 closed
docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------
kafka-cluster_kafka-1_1_c79e5ef5d397 /etc/confluent/docker/run Exit 0
kafka-cluster_kafka-2_1_d4399ed0a670 /etc/confluent/docker/run Exit 0
kafka-cluster_kafka-3_1_2df6f47759c0 /etc/confluent/docker/run Exit 0
kafka-cluster_zookeeper-1_1_8bbd729b09d8 /etc/confluent/docker/run Up
kafka-cluster_zookeeper-2_1_c9f58ba3fbc8 /etc/confluent/docker/run Up
kafka-cluster_zookeeper-3_1_31e4762a61bb /etc/confluent/docker/run Up
docker apache-kafka docker-compose
I have a confluent kafka setup and docker-compose.yml file
https://github.com/confluentinc/cp-docker-images/blob/5.0.0-post/examples/kafka-cluster/docker-compose.yml
I have edited the file and added the ports option to the docker compose file so that I can access them outside of the host.
---
version: '2'
services:
zookeeper-1:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 22181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
zookeeper-2:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 2
ZOOKEEPER_CLIENT_PORT: 32181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
zookeeper-3:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_SERVER_ID: 3
ZOOKEEPER_CLIENT_PORT: 42181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
network_mode: "host"
kafka-1:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "19092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:19092
network_mode: "host"
kafka-2:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "29092"
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092
network_mode: "host"
kafka-3:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
ports:
- "39092"
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:39092
network_mode: "host"
I have run the following commands:
docker-compose up --no-start
docker-compose start zookeeper-1
docker-compose start zookeeper-2
docker-compose start zookeeper-3
docker-compose run -d --service-ports kafka-1
docker-compose run -d --service-ports kafka-2
docker-compose run -d --service-ports kafka-3
The zookeeper-1,2,3 started but kafka-1 failed with exit code 0.
When I do docker-compose start kafka-1, the ports are not exposed but the service is started.
The output of the above commands:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7abec60edd7a confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-2_1_c9f58ba3fbc8
68ec403740d6 confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-3_1_31e4762a61bb
69d6645487aa confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 3 minutes ago Up 3 minutes kafka-cluster_zookeeper-1_1_8bbd729b09d8
docker logs of kafka-1, kafka-2, kafka-3 (all are same)
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/127.0.0.1:42181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/127.0.0.1:42181, initiating session
[main-SendThread(localhost:42181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:32181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/0:0:0:0:0:0:0:1:32181, initiating session
[main-SendThread(localhost:32181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:22181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to localhost/0:0:0:0:0:0:0:1:22181, initiating session
[main-SendThread(localhost:22181)] INFO org.apache.zookeeper.ClientCnxn - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
[main] ERROR io.confluent.admin.utils.ClusterStatus - Timed out waiting for connection to Zookeeper server [localhost:22181,localhost:32181,localhost:42181].
[main] INFO org.apache.zookeeper.ZooKeeper - Session: 0x0 closed
docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------
kafka-cluster_kafka-1_1_c79e5ef5d397 /etc/confluent/docker/run Exit 0
kafka-cluster_kafka-2_1_d4399ed0a670 /etc/confluent/docker/run Exit 0
kafka-cluster_kafka-3_1_2df6f47759c0 /etc/confluent/docker/run Exit 0
kafka-cluster_zookeeper-1_1_8bbd729b09d8 /etc/confluent/docker/run Up
kafka-cluster_zookeeper-2_1_c9f58ba3fbc8 /etc/confluent/docker/run Up
kafka-cluster_zookeeper-3_1_31e4762a61bb /etc/confluent/docker/run Up
docker apache-kafka docker-compose
docker apache-kafka docker-compose
edited Nov 7 at 10:03
asked Nov 7 at 6:05
JavaTechnical
2,20742456
2,20742456
what doesdocker pssay?
– freakman
Nov 7 at 8:16
what's the output ofdocker-compose ps? and ofdocker-compose logs kafka-1?
– Robin Moffatt
Nov 7 at 8:26
@freakman I attached the output and logs
– JavaTechnical
Nov 7 at 9:42
1
can you remove the ports and try, since you are already using "host" as the network mode you should be able to access the kafka
– Ntwobike
Nov 7 at 10:21
1
Check out the answer here: stackoverflow.com/questions/51086884/… Might help.
– Bitswazsky
Nov 7 at 12:08
|
show 6 more comments
what doesdocker pssay?
– freakman
Nov 7 at 8:16
what's the output ofdocker-compose ps? and ofdocker-compose logs kafka-1?
– Robin Moffatt
Nov 7 at 8:26
@freakman I attached the output and logs
– JavaTechnical
Nov 7 at 9:42
1
can you remove the ports and try, since you are already using "host" as the network mode you should be able to access the kafka
– Ntwobike
Nov 7 at 10:21
1
Check out the answer here: stackoverflow.com/questions/51086884/… Might help.
– Bitswazsky
Nov 7 at 12:08
what does
docker ps say?– freakman
Nov 7 at 8:16
what does
docker ps say?– freakman
Nov 7 at 8:16
what's the output of
docker-compose ps? and of docker-compose logs kafka-1 ?– Robin Moffatt
Nov 7 at 8:26
what's the output of
docker-compose ps? and of docker-compose logs kafka-1 ?– Robin Moffatt
Nov 7 at 8:26
@freakman I attached the output and logs
– JavaTechnical
Nov 7 at 9:42
@freakman I attached the output and logs
– JavaTechnical
Nov 7 at 9:42
1
1
can you remove the ports and try, since you are already using "host" as the network mode you should be able to access the kafka
– Ntwobike
Nov 7 at 10:21
can you remove the ports and try, since you are already using "host" as the network mode you should be able to access the kafka
– Ntwobike
Nov 7 at 10:21
1
1
Check out the answer here: stackoverflow.com/questions/51086884/… Might help.
– Bitswazsky
Nov 7 at 12:08
Check out the answer here: stackoverflow.com/questions/51086884/… Might help.
– Bitswazsky
Nov 7 at 12:08
|
show 6 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
The problem here is that in KAFKA_ADVERTISED_LISTENERS must be set to the IP address of the host. So that when you run it on another machine, that machine will be able to access the kafka using the IP address.
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.1.1.1:39092
Next point, pointed out by @Ntwobike is to remove the -p option. Not that it is not needed, but it is redundant when the --net=host option is set.
Most important, is to check the firewall. Check the iptables rules and change them to FORWARD ACCEPT (in my case I have done so,since mine is a development host).
If you are using CentOS or RHEL, you can try stopping the firewalld and check to see if it is the firewall that is creating the problem.
systemctl stop firewalld
For others, it is ufw (Ubuntu, Mint)
systemctl stop ufw
Alternatively, you can also do an iptables -F but before that make sure that you backup your iptables rules using
iptables-save > /home/iptables_rules_bak
and then after flushing the rules, you can do
iptables -P FORWARD ACCEPT
1
It's not clear why you had to edit the Compose file on Github. It already works for inside and outside the Docker network. rmoff.net/2018/08/02/kafka-listeners-explained
– cricket_007
Nov 7 at 13:57
@cricket_007 But, somehow it did not work for me! I had to edit the advertised listeners
– JavaTechnical
Nov 7 at 14:33
Right, you need to edit that anyway, but it doesn't have to be the host IP
– cricket_007
Nov 7 at 15:08
add a comment |
up vote
0
down vote
If you look at the all-in-one Compose example by Confluent, then everything is setup correctly for broker access in all directions, and not using network: host "hacks" (which only would work on Linux)
Refer
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_HOST://localhost:29092
Outside of the Docker network, you can connect via port 29092, but within, it's 9092
More importantly, the Zookeeper connection strings should actually point at one another, not localhost
I would also like to point out that multiple brokers on one machine doesn't have many benefits, and if you want persistent data (don't lose everything if you restart your computer, or Docker), you'll want volume mounts
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The problem here is that in KAFKA_ADVERTISED_LISTENERS must be set to the IP address of the host. So that when you run it on another machine, that machine will be able to access the kafka using the IP address.
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.1.1.1:39092
Next point, pointed out by @Ntwobike is to remove the -p option. Not that it is not needed, but it is redundant when the --net=host option is set.
Most important, is to check the firewall. Check the iptables rules and change them to FORWARD ACCEPT (in my case I have done so,since mine is a development host).
If you are using CentOS or RHEL, you can try stopping the firewalld and check to see if it is the firewall that is creating the problem.
systemctl stop firewalld
For others, it is ufw (Ubuntu, Mint)
systemctl stop ufw
Alternatively, you can also do an iptables -F but before that make sure that you backup your iptables rules using
iptables-save > /home/iptables_rules_bak
and then after flushing the rules, you can do
iptables -P FORWARD ACCEPT
1
It's not clear why you had to edit the Compose file on Github. It already works for inside and outside the Docker network. rmoff.net/2018/08/02/kafka-listeners-explained
– cricket_007
Nov 7 at 13:57
@cricket_007 But, somehow it did not work for me! I had to edit the advertised listeners
– JavaTechnical
Nov 7 at 14:33
Right, you need to edit that anyway, but it doesn't have to be the host IP
– cricket_007
Nov 7 at 15:08
add a comment |
up vote
0
down vote
The problem here is that in KAFKA_ADVERTISED_LISTENERS must be set to the IP address of the host. So that when you run it on another machine, that machine will be able to access the kafka using the IP address.
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.1.1.1:39092
Next point, pointed out by @Ntwobike is to remove the -p option. Not that it is not needed, but it is redundant when the --net=host option is set.
Most important, is to check the firewall. Check the iptables rules and change them to FORWARD ACCEPT (in my case I have done so,since mine is a development host).
If you are using CentOS or RHEL, you can try stopping the firewalld and check to see if it is the firewall that is creating the problem.
systemctl stop firewalld
For others, it is ufw (Ubuntu, Mint)
systemctl stop ufw
Alternatively, you can also do an iptables -F but before that make sure that you backup your iptables rules using
iptables-save > /home/iptables_rules_bak
and then after flushing the rules, you can do
iptables -P FORWARD ACCEPT
1
It's not clear why you had to edit the Compose file on Github. It already works for inside and outside the Docker network. rmoff.net/2018/08/02/kafka-listeners-explained
– cricket_007
Nov 7 at 13:57
@cricket_007 But, somehow it did not work for me! I had to edit the advertised listeners
– JavaTechnical
Nov 7 at 14:33
Right, you need to edit that anyway, but it doesn't have to be the host IP
– cricket_007
Nov 7 at 15:08
add a comment |
up vote
0
down vote
up vote
0
down vote
The problem here is that in KAFKA_ADVERTISED_LISTENERS must be set to the IP address of the host. So that when you run it on another machine, that machine will be able to access the kafka using the IP address.
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.1.1.1:39092
Next point, pointed out by @Ntwobike is to remove the -p option. Not that it is not needed, but it is redundant when the --net=host option is set.
Most important, is to check the firewall. Check the iptables rules and change them to FORWARD ACCEPT (in my case I have done so,since mine is a development host).
If you are using CentOS or RHEL, you can try stopping the firewalld and check to see if it is the firewall that is creating the problem.
systemctl stop firewalld
For others, it is ufw (Ubuntu, Mint)
systemctl stop ufw
Alternatively, you can also do an iptables -F but before that make sure that you backup your iptables rules using
iptables-save > /home/iptables_rules_bak
and then after flushing the rules, you can do
iptables -P FORWARD ACCEPT
The problem here is that in KAFKA_ADVERTISED_LISTENERS must be set to the IP address of the host. So that when you run it on another machine, that machine will be able to access the kafka using the IP address.
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.1.1.1:39092
Next point, pointed out by @Ntwobike is to remove the -p option. Not that it is not needed, but it is redundant when the --net=host option is set.
Most important, is to check the firewall. Check the iptables rules and change them to FORWARD ACCEPT (in my case I have done so,since mine is a development host).
If you are using CentOS or RHEL, you can try stopping the firewalld and check to see if it is the firewall that is creating the problem.
systemctl stop firewalld
For others, it is ufw (Ubuntu, Mint)
systemctl stop ufw
Alternatively, you can also do an iptables -F but before that make sure that you backup your iptables rules using
iptables-save > /home/iptables_rules_bak
and then after flushing the rules, you can do
iptables -P FORWARD ACCEPT
answered Nov 7 at 12:14
JavaTechnical
2,20742456
2,20742456
1
It's not clear why you had to edit the Compose file on Github. It already works for inside and outside the Docker network. rmoff.net/2018/08/02/kafka-listeners-explained
– cricket_007
Nov 7 at 13:57
@cricket_007 But, somehow it did not work for me! I had to edit the advertised listeners
– JavaTechnical
Nov 7 at 14:33
Right, you need to edit that anyway, but it doesn't have to be the host IP
– cricket_007
Nov 7 at 15:08
add a comment |
1
It's not clear why you had to edit the Compose file on Github. It already works for inside and outside the Docker network. rmoff.net/2018/08/02/kafka-listeners-explained
– cricket_007
Nov 7 at 13:57
@cricket_007 But, somehow it did not work for me! I had to edit the advertised listeners
– JavaTechnical
Nov 7 at 14:33
Right, you need to edit that anyway, but it doesn't have to be the host IP
– cricket_007
Nov 7 at 15:08
1
1
It's not clear why you had to edit the Compose file on Github. It already works for inside and outside the Docker network. rmoff.net/2018/08/02/kafka-listeners-explained
– cricket_007
Nov 7 at 13:57
It's not clear why you had to edit the Compose file on Github. It already works for inside and outside the Docker network. rmoff.net/2018/08/02/kafka-listeners-explained
– cricket_007
Nov 7 at 13:57
@cricket_007 But, somehow it did not work for me! I had to edit the advertised listeners
– JavaTechnical
Nov 7 at 14:33
@cricket_007 But, somehow it did not work for me! I had to edit the advertised listeners
– JavaTechnical
Nov 7 at 14:33
Right, you need to edit that anyway, but it doesn't have to be the host IP
– cricket_007
Nov 7 at 15:08
Right, you need to edit that anyway, but it doesn't have to be the host IP
– cricket_007
Nov 7 at 15:08
add a comment |
up vote
0
down vote
If you look at the all-in-one Compose example by Confluent, then everything is setup correctly for broker access in all directions, and not using network: host "hacks" (which only would work on Linux)
Refer
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_HOST://localhost:29092
Outside of the Docker network, you can connect via port 29092, but within, it's 9092
More importantly, the Zookeeper connection strings should actually point at one another, not localhost
I would also like to point out that multiple brokers on one machine doesn't have many benefits, and if you want persistent data (don't lose everything if you restart your computer, or Docker), you'll want volume mounts
add a comment |
up vote
0
down vote
If you look at the all-in-one Compose example by Confluent, then everything is setup correctly for broker access in all directions, and not using network: host "hacks" (which only would work on Linux)
Refer
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_HOST://localhost:29092
Outside of the Docker network, you can connect via port 29092, but within, it's 9092
More importantly, the Zookeeper connection strings should actually point at one another, not localhost
I would also like to point out that multiple brokers on one machine doesn't have many benefits, and if you want persistent data (don't lose everything if you restart your computer, or Docker), you'll want volume mounts
add a comment |
up vote
0
down vote
up vote
0
down vote
If you look at the all-in-one Compose example by Confluent, then everything is setup correctly for broker access in all directions, and not using network: host "hacks" (which only would work on Linux)
Refer
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_HOST://localhost:29092
Outside of the Docker network, you can connect via port 29092, but within, it's 9092
More importantly, the Zookeeper connection strings should actually point at one another, not localhost
I would also like to point out that multiple brokers on one machine doesn't have many benefits, and if you want persistent data (don't lose everything if you restart your computer, or Docker), you'll want volume mounts
If you look at the all-in-one Compose example by Confluent, then everything is setup correctly for broker access in all directions, and not using network: host "hacks" (which only would work on Linux)
Refer
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_HOST://localhost:29092
Outside of the Docker network, you can connect via port 29092, but within, it's 9092
More importantly, the Zookeeper connection strings should actually point at one another, not localhost
I would also like to point out that multiple brokers on one machine doesn't have many benefits, and if you want persistent data (don't lose everything if you restart your computer, or Docker), you'll want volume mounts
answered Nov 7 at 14:01
cricket_007
75.4k1042105
75.4k1042105
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184333%2funable-to-access-kafka-from-outside-docker%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
what does
docker pssay?– freakman
Nov 7 at 8:16
what's the output of
docker-compose ps? and ofdocker-compose logs kafka-1?– Robin Moffatt
Nov 7 at 8:26
@freakman I attached the output and logs
– JavaTechnical
Nov 7 at 9:42
1
can you remove the ports and try, since you are already using "host" as the network mode you should be able to access the kafka
– Ntwobike
Nov 7 at 10:21
1
Check out the answer here: stackoverflow.com/questions/51086884/… Might help.
– Bitswazsky
Nov 7 at 12:08