0

I have a kafka cluster installed in my local windows machine, and I would like to access this cluster from my spring boot application deployed as a container in docker toolbox, here is my application.properties file.

kafka.bootstrapAddress = 127.0.0.1:9092

And when I launch the container I use the host network but it doesn't work.

docker run spring-app:latest --network host

So how can i access this cluster. ? Thank you in advance.

Belgacem
  • 183
  • 9
  • Do you get any error messages? Can you elaborate on what would you have expected and what does not work? Does it make a difference if you replace 127.0.0.1 by 0.0.0.0? – Philipp Claßen May 03 '20 at 16:04
  • Docker Toolbox runs in a dedicated VM, so "host" networking uses the VM's network (not the physical host outside of that). If the process were running directly on the VM and not in Docker, how would it reach the Kafka broker? – David Maze May 03 '20 at 16:14
  • Yes that's exactly what I'm looking for, how I can bind the virtual machine network to the local machine network, so when I use 127.0.0.1 Docker Toolbox connects to the local machine and not to the virtual machine. – Belgacem May 03 '20 at 18:40

1 Answers1

0

From the docker run reference, the docker run command usage is like this:

$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

You are not providing the --network option correctly. The option must come before the image name and whatever comes after the image name will be passed to the created container as the command and arguments.

Here is how you should invoke the command to correct your issue:

$ docker run --network host spring-app:latest
Mahdi AlKhalaf
  • 101
  • 1
  • 1
  • 6