0

I have running in my local Windows an ActiveMQ service:

  netstat -an|find "61613"
  TCP    0.0.0.0:61613          0.0.0.0:0              LISTENING
  TCP    127.0.0.1:58179        127.0.0.1:61613        ESTABLISHED
  TCP    127.0.0.1:58236        127.0.0.1:61613        ESTABLISHED
  TCP    127.0.0.1:61613        127.0.0.1:58179        ESTABLISHED
  TCP    127.0.0.1:61613        127.0.0.1:58236        ESTABLISHED
  TCP    [::]:61613             [::]:0                 LISTENING

And I have a Docker container built from a Dockerfile that tries to connect to it with the Python code:

import stomp
conn = stomp.Connection12([('host.docker.internal', 61613)])
conn.connect('admin', 'admin', wait=True)

This Python code works fine if I run it in my computer, but from Docker I get the error:

Could not connect to host host.docker.internal, port 61613
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/stomp/transport.py", line 734, in attempt_connection
    self.socket = get_socket(host_and_port[0], host_and_port[1], self.__timeout)
  File "/usr/local/lib/python3.9/site-packages/stomp/backwardsock26.py", line 16, in get_socket
    return socket.create_connection((host, port), timeout)
  File "/usr/local/lib/python3.9/socket.py", line 844, in create_connection
    raise err
  File "/usr/local/lib/python3.9/socket.py", line 832, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

If I enter into the Docker container and run ping host.docker.internal, it works:

root@ab397fb7a8ae:/# ping host.docker.internal
PING host.docker.internal (192.168.1.66) 56(84) bytes of data.
64 bytes from host.docker.internal (192.168.1.66): icmp_seq=1 ttl=126 time=0.556 ms
64 bytes from host.docker.internal (192.168.1.66): icmp_seq=2 ttl=126 time=0.351 ms
64 bytes from host.docker.internal (192.168.1.66): icmp_seq=3 ttl=126 time=0.591 ms
...
64 bytes from host.docker.internal (192.168.1.66): icmp_seq=18 ttl=126 time=0.382 ms
^C
--- host.docker.internal ping statistics ---
18 packets transmitted, 18 received, 0% packet loss, time 17028ms
rtt min/avg/max/mdev = 0.341/0.573/0.911/0.150 ms

However, if I try to ping the specific port, it doesn't work:

root@ab397fb7a8ae:/# nc -vv host.docker.internal 61613
nc: connect to host.docker.internal (192.168.1.66) port 61613 (tcp) failed: Connection timed out

I have tried adding this line to the Dockerfile

EXPOSE 61613

And connecting to the port 0 like

conn = stomp.Connection12([('host.docker.internal', 0)])

but it still doesnt work.

How can I solve this?

I have read the following questions, but I didn't find the solution in any of them:

Justin Bertram
  • 22,975
  • 3
  • 16
  • 38
Javier Lopez Tomas
  • 1,593
  • 1
  • 16
  • 30

0 Answers0