<p>Maybe your service only listen from 127.0.0.1 host so that connect from docker container failed since the mapped host is 172.17.0.1. You can try use port-mapping for docker so that you can access to your server's service from localhost(127.0.0.1)</p>
<pre><code>docker run -p 30305:30305 -it --rm alpine /bin/ash 
</code></pre>

CC BY-SA 4.0
2024-10-23T03:48:18.590Z
2024-10-23T03:48:18.590Z
Hiếu Vũ
<p>On the host I check connectivity to the serivice via the port:</p>
<pre><code>telnet 127.0.0.1 30305
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
</code></pre>
<p>Now I want to connect from inside a container...</p>
<p>I start the container like this:</p>
<pre><code>docker run -it --add-host james:host-gateway  --rm alpine /bin/ash 
</code></pre>
<p>then install telnet like this:</p>
<pre><code>apk update
apk add busybox-extras
</code></pre>
<p>check that the special host-ip resolves, like this:</p>
<pre><code>ping james
PING james (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: seq=0 ttl=64 time=0.082 ms
</code></pre>
<p>however:</p>
<pre><code>telnet james 30305
</code></pre>
<p>Simply hangs forever</p>
<p>What can be the issue?</p>
<p>I know it is a Docker networking issue, because I ran the 30305 service on a totally different server, and it connects fine, the issue is ONLY when the service is running on the SAME machine as Docker.</p>
<p>I'm assuming this special Docker host-ip trick is all local and doesn't touch the firewall.</p>

<docker><linux>
Connecting to service on host port from inside Docker container, ping works (address resolves) but telnet fails
struggle-session
# Connecting to service on host port from inside Docker container, ping works (address resolves) but telnet fails

(Asked by: username_0 on 2024-10-22)

On the host I check connectivity to the serivice via the port:
telnet 127.0.0.1 30305
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

Now I want to connect from inside a container...
I start the container like this:
docker run -it --add-host james:host-gateway  --rm alpine /bin/ash 

then install telnet like this:
apk update
apk add busybox-extras

check that the special host-ip resolves, like this:
ping james
PING james (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: seq=0 ttl=64 time=0.082 ms

however:
telnet james 30305

Simply hangs forever
What can be the issue?
I know it is a Docker networking issue, because I ran the 30305 service on a totally different server, and it connects fine, the issue is ONLY when the service is running on the SAME machine as Docker.
I'm assuming this special Docker host-ip trick is all local and doesn't touch the firewall.

**Tags:** docker, linux


---

## 1 answers

### Answer by username_1 on 2024-10-23. Score: 0

Maybe your service only listen from 127.0.0.1 host so that connect from docker container failed since the mapped host is 172.17.0.1. You can try use port-mapping for docker so that you can access to your server's service from localhost(127.0.0.1)
docker run -p 30305:30305 -it --rm alpine /bin/ash


---

