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!

  • what is the default password of CoreOS? [closed]
  • Is it possible to commit only a subset of the changes to a docker image?
  • Using mongo with docker and nfs storage
  • TravisCI build succeeds even when tests fail
  • Cannot run .exe (unsigned?) applications inside nanoserver
  • WordPress NGINX conf routes back to Landing Page
  • Unable to install packages using Docker on Mac
  • GitlabCI free shared runners to provision Ubuntu instead of CoreOS?
  • change db:5432 to 127.0.0.1:5432 in docker-compose file
  • sbt failed download in running play docker container
  • Docker compose linking appears to not work
  • Docker deployment update shared volume
  • 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.