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 :-
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
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?
One Solution collect form web for “Cannot produce message to kafka from service running in docker”
In real life,
advertised.host.name should never be
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
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.