publishing message to external Kafka Broker from docker container

In my IDE, I am able to utilize a spring-boot application that would produce message(with Kafkaproducer) to an external kafka broker. But once I have hosted my spring-boot application in docker container, my application can no longer submit to the broker.
Here is the error message:

    o.s.k.support.LoggingProducerListener: Exception thrown when sending a message with key='null' and payload='....' to topic Category: 
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
    org.springframework.kafka.core.KafkaProducerException: 
Failed to send; nested exception is org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.

what I used to run docker was: docker run -p 9001:9001 -d image_name in which 9001 is my spring-boot port, I am able to Post to the port, just that once my message was posted, it won’t get to the external broker.
I think I have the general concept that Docker containers are living in isolated land where you have to open/map the port in order to access it(like my -p 9002:9002), but does it work the same way to access out from container? if so, can someone please show me how I can run the docker container in order to be able to access to the external broker(let’s say the broker URL is “192.168.1.1:9000”)? I don’t think I am able to modify anything on the broker now, but my assumption is that if I can access via my IDE, why not in docker? Thanks for all the help!

  • pdf2htmlEX cannot open or read file
  • Kubernetes error pulling of local registry
  • Publishing a message to Kafka running inside docker
  • Access to Docker Container Port
  • Mesos execute fails with `HTTP/1.1 401 Unauthorized` error
  • mysql_config_editor with docker
  • Installing elasticsearch docker image fails on command not found
  • How to convert a systemctl command to supervisord command
  • Docker containers can't access local network DNS
  • how to enable docker remote api on windows-10
  • Reverse proxy to WordPress container
  • Docker Container npm global affect host or only container?
  • One Solution collect form web for “publishing message to external Kafka Broker from docker container”

    it was due to my ip-forwarding = 0, once that is turned on I am able to do outgoing request.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.