Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

875
Visualizações
how to connect to localhost:9092 from docker container using docker-compose and not using docker bridge

I am running Kafka server on my local machine on port 9092. I am running a service in docker container using docker-compose which needs to send message to kafka server.

I tried writing my producer in service code using 'localhost' and IP as well but both are not working.

Can anyone help me to fix the issue?

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

With docker-compose:

Use the network_mode option to allow connection to localhost ports

network_mode: "host"

Without docker-compose:

Use the --net flag to allow connection to localhost ports

docker run -it --net=host

You can also use --network flag

--network="host"

According to the official Docker documentation these "give the container full access to local system services such as D-bus and is therefore considered insecure."

Of course if you containerise your service that is running on localhost:9092 then you could run that in a Docker container too and link your two Docker containers together using the --link flag:

docker run -t -d myService
docker run -t -d --link myService:myService_ref myOtherService
about 4 years ago · Santiago Trujillo Relatório

0

You could fix the IP address of your host and pass this to docker via docker-compose using the 'extra_hosts' option:

Something like:

sudo ifconfig lo0 alias 172.16.123.1 

Then in docker compose:

extra_hosts:
 - "service.localhost:172.16.123.1"

Then within the container you should be able to:

ping service.localhost
about 4 years ago · Santiago Trujillo Relatório

0

Connect from container to local machine. Make IP alias for localhost

sudo ifconfig lo:0 172.18.1.1 up

Add to docker-compose config service lines

extra_hosts:
      - 'local.machine:172.18.1.1'

And after container restart it can be used to connect

'web-socket-server' => 'ws://172.18.1.1',
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda