Akhil
Akhil

Reputation: 1264

Cannot produce message to kafka from service running in docker

I've a rest service running in docker container on port 5000 which is used to produce message over kafka topic running out of docker container.

I've configure my producer client with below properties :-

bootstrap.servers=localhost:9093

And I've started my contained with below command:-

docker run -d -p 127.0.0.1:5000:5000 <contained id>

I've also made below configuration to advertise kafka host and port

advertised.host.name=localhost
advertised.port=9093

Despite of having all configuration when I try to produce to a kafka topic then I get below error:-

org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.

Can someone please point where the actual problem is?

Upvotes: 4

Views: 1235

Answers (1)

serejja
serejja

Reputation: 23881

In real life, advertised.host.name should never be localhost.

In your case, you run your Docker container in bridge networking mode, so it won't be able to reach the broker via localhost, as it will point to the container network, not the host machine.

To make it work you should set the advertised.host.name and bootstrap.servers to the IP address returned by ifconfig docker0 (might be not docker0 in your case but you get the point).

Alternatively, you may probably run your container with --net=host, but I think you'd better properly configure the advertised host name.

Upvotes: 3

Related Questions