Reputation: 1194
I have a docker container image which produces some messages to topic of kafka which is running outside container in the same node/machine.
When i run the docker container to publish some messages to topic of kafka getting below error.
[root@lm--mro-cloudnative--central docker_producer]# docker run test-producer %3|1544419029.623|FAIL|rdkafka#producer-1| [thrd:lm--mro-cloudnative--central.novalocal:9092/0]: lm--mro-cloudnative--central.novalocal:9092/0: Failed to resolve 'lm-cloudnative--central.novalocal:9092': Name or service not known (after 342076146ms in state INIT)
%3|1544419029.623|ERROR|rdkafka#producer-1| [thrd:lm--mro-cloudnative--central.novalocal:9092/0]: lm--cloudnative--central.novalocal:9092/0: Failed to resolve 'lm-cloudnative--central.novalocal:9092': Name or service not known (after 342076146ms in state INIT)
My producer python code as below,(producer.py)
from confluent_kafka import Producer
import json
data = {"name":"LTE", "parameters":{"Period":1},"targets":[88054]}
conf = {'bootstrap.servers': 'localhost:9092',
'default.topic.config': {'produce.offset.report': True, 'request.required.acks' : -1}}
p = Producer(**conf)
json_data = json.dumps(data)
p.produce('mro_topic', key='MRO', value=json_data, callback=None)
p.flush(30)
Dockerfile
FROM registry-access-redhat-com.repo.lab.pl.**-**.com/rhel7.4
# CONFIGURE YUM
RUN rm -f /etc/yum.repos.d/*
ADD resources/yum.repos.d/* /etc/yum.repos.d/
RUN echo "sslverify=false" >> /etc/yum.conf
RUN yum install -y python-pip
RUN pip install --index-url https://repo.lab.pl.**.com/api/pypi/python/simple/ pip
RUN pip install --index-url https://repo.lab.pl.**.com/api/pypi/python/simple/ requests
RUN pip --version
RUN pip install --index-url https://repo.lab.pl.**.com/api/pypi/python/simple/ setuptools
RUN pip install --index-url https://repo.lab.pl.**.com/api/pypi/python/simple/ confluent-kafka
RUN pip install --index-url https://repo.lab.pl.**.com/api/pypi/python/simple/ avro
ADD producer.py /
CMD [ "python", "producer.py" ]
docker build -t test-producer .
docker run test-producer
Is there anyting i missed ?
Upvotes: 0
Views: 882
Reputation: 678
With host as "localhost:9092" it won't work because it points to the same docker container not to the node/machine.
Solution: Instead of localhost use IP address of node/machine then it should work.
Upvotes: 2