0

I have a simple Java application that runs in the command line and connects to a local Apache Pulsar on port 6650 (pulsar://localhost:6650). I've jar'ed the application and dockerised it. The Apache Pulsar server is on the same machine as the dockerised app. However, when I run the docker container, it says Connection refused: localhost/127.0.0.1:6650.

I'm new to Docker so I believe it may be something I'm doing wrong with Docker. I've tried the following commands to run my container:

docker run -it -p 6650:6650 pulsar_logging_consumer
docker run -it --network="host" pulsar_logging_consumer

Dockerfile:

FROM openjdk:latest
COPY target/pulsar_logging_consumer-1.0-SNAPSHOT-jar-with-dependencies.jar /usr/src/pulsar_logging_consumer-1.0-SNAPSHOT-jar-with-dependencies.jar
EXPOSE 6650
CMD java -jar /usr/src/pulsar_logging_consumer-1.0-SNAPSHOT-jar-with-dependencies.jar
leopal
  • 4,238
  • 1
  • 27
  • 33
doctopus
  • 4,787
  • 7
  • 39
  • 81
  • 1
    Probably problem is that each of container is in different network.You can use bridge to set connection between it: https://docs.docker.com/network/network-tutorial-standalone/ – quentino Jun 26 '20 at 08:47
  • 2
    Does this answer your question? [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – leopal Jun 26 '20 at 09:37
  • 1
    Yup, turns out I need to use `host.docker.internal` because I'm on a mac. – doctopus Jun 26 '20 at 09:53

0 Answers0