# Localhost connection refused with beta9

**URL:** <https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478>\
**Category:** Docker Desktop\
**Tags:** macos\
**Created:** [April 29, 2016, 8:20am UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478 "2016-04-29T08:20:16Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![roughy](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/roughy/32/8398_2.png) [@roughy](https://forums.docker.com/u/roughy)\
**Post date:** [April 29, 2016, 8:20am UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/1 "2016-04-29T08:20:16Z")

</div>

### Expected behavior

> $\> curl -v localhost  
> Connected to localhost (127.0.0.1) port 80 (#0)  
> GET / HTTP/1.1  
> Host: localhost:80  
> User-Agent: curl/7.43.0  
> Accept: _/_

> HTTP/1.1 200 OK

### Actual behavior

> $\> curl -v localhost  
> Rebuilt URL to: localhost/  
> Trying 127.0.0.1…  
> connect to 127.0.0.1 port 80 failed: Connection refused

### Information

- the output of:
  - `pinata diagnose -u` on OSX

> OS X: version 10.11.4 (build: 15E65)  
> Docker.app: version v1.11.0-beta9  
> Running diagnostic tests:  
> [OK] docker-cli  
> [OK] Moby booted  
> [OK] driver.amd64-linux  
> [OK] vmnetd  
> [OK] osxfs  
> [OK] db  
> [OK] slirp  
> [OK] menubar  
> [OK] environment  
> [OK] Docker  
> [OK] VT-x  
> Docker logs are being collected into /tmp/20160429-100854.tar.gz  
> Most specific failure is: No error was detected  
> Your unique id is: 526A566B-2949-46D1-B35F-D9A82CD08D3F

In my docker-compose.yml I configured `network_mode: "host"` for all container. When I remove this setting then the container is accessible but the containers are not able to communicate to each other anymore.

Example docker-compose.yml

> services:

> frontend  
> build: frontend  
> ports:  
> - “8080:8080”  
> network\_mode: “host”

> backend:  
> build: backend  
> ports:  
> - “8081:8081”  
> network\_mode: “host”

> haproxy:  
> build: haproxy  
> ports:  
> - “80:80”  
> - “443:443”  
> network\_mode: “host”

### Steps to reproduce the behavior

1. docker-compose up -d
2. curl -v localhost

---

<div class="post-metadata">

**Author:** ![roughy](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/roughy/32/8398_2.png) [@roughy](https://forums.docker.com/u/roughy)\
**Post date:** [May 11, 2016, 8:06am UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/2 "2016-05-11T08:06:47Z")

</div>

Still not working Version 1.11.1-beta11 (build: 6974) 😢

---

<div class="post-metadata">

**Author:** ![mnawalany](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/mnawalany/32/10813_2.png) [@mnawalany](https://forums.docker.com/u/mnawalany)\
**Post date:** [May 30, 2016, 2:41pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/3 "2016-05-30T14:41:17Z")

</div>

Version 1.11.1-beta13.1 (build: 8193) still have the same problem. Could you please advise some workaround?

---

<div class="post-metadata">

**Author:** ![roughy](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/roughy/32/8398_2.png) [@roughy](https://forums.docker.com/u/roughy)\
**Post date:** [May 31, 2016, 5:23pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/4 "2016-05-31T17:23:41Z")

</div>

I have no workaround, yet

---

<div class="post-metadata">

**Author:** ![hyunk3l](https://avatars.discourse-cdn.com/v4/letter/h/f04885/32.png) [@hyunk3l](https://forums.docker.com/u/hyunk3l)\
**Post date:** [June 3, 2016, 2:26pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/5 "2016-06-03T14:26:51Z")

</div>

Same problem here…

---

<div class="post-metadata">

**Author:** ![curtisrcooley](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@curtisrcooley](https://forums.docker.com/u/curtisrcooley)\
**Post date:** [June 9, 2016, 10:51pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/6 "2016-06-09T22:51:18Z")

</div>

> [@roughy](#):
>
> In my docker-compose.yml I configured network\_mode: “host” for all container. When I remove this setting then the container is accessible but the containers are not able to communicate to each other anymore.

This is exactly the behavior I see. It seems I can either have the containers link to each other or access a port from the container from my mac, but not both.

I really wish this was listed in the known issues in the updates. I feel this has been deemed “too hard” and is being ignored. From what I’ve read, it’s a hard problem, but it’s a problem and needs to be recognized as such.

---

<div class="post-metadata">

**Author:** ![lyleh](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/lyleh/32/11184_2.png) [@lyleh](https://forums.docker.com/u/lyleh)\
**Post date:** [June 16, 2016, 11:02pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/7 "2016-06-16T23:02:10Z")

</div>

Looks like I’m having a similar issue on 1.11.2-beta15. Interestingly, if I refer to my service at 127.0.0.1 it works, but not localhost:

> $ curl -v localhost
> 
> - Rebuilt URL to: localhost/
> - Trying ::1…
> - Connected to localhost (::1) port 80 (#0)
> 
> > GET / HTTP/1.1  
> > Host: localhost  
> > User-Agent: curl/7.43.0  
> > Accept: _/_
> 
> - Empty reply from server
> - Connection #0 to host localhost left intact  
> curl: (52) Empty reply from server

> $ curl -v 127.0.0.1
> 
> - Rebuilt URL to: 127.0.0.1/
> - Trying 127.0.0.1…
> - Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> 
> > GET / HTTP/1.1  
> > Host: 127.0.0.1  
> > User-Agent: curl/7.43.0  
> > Accept: _/_
> 
> \< HTTP/1.1 404 Not Found  
> \< Server: Apache-Coyote/1.1  
> \< Content-Length: 0  
> \< Date: Thu, 16 Jun 2016 22:54:22 GMT  
> \<
> 
> - Connection #0 to host 127.0.0.1 left intact

Note that the 404 is expected from my app.

What looks interesting to me is the part in the failed command that says:

> - Rebuilt URL to: localhost/
> - Trying ::1…

Here’s my `/etc/hosts`:

```
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

```

It looks like localhost is being resolved to the IPv6 address for some reason? Commenting that last line out of my `/etc/hosts` file cures the problem, but I’m not sure what other consequences that might have down the line.

And oddly, I have a different app (using `docker-compose`) which works just fine even without the `/etc/hosts` mod.

---

<div class="post-metadata">

**Author:** ![adyach](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@adyach](https://forums.docker.com/u/adyach)\
**Post date:** [July 8, 2016, 1:37pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/8 "2016-07-08T13:37:24Z")

</div>

The same issue for Version 1.12.0-rc2-beta17 (build: 9779) ff18c0c63c5ff3c4a4a925d191d5592d655779d. Do we have issue for that ?

---

<div class="post-metadata">

**Author:** ![cooperaj](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/cooperaj/32/12171_2.png) [@cooperaj](https://forums.docker.com/u/cooperaj)\
**Post date:** [July 8, 2016, 6:28pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/9 "2016-07-08T18:28:54Z")

</div>

I’ve spent 4 or so hours today attempting to set up a Redis cluster (which requires host networking) for dev work and this has apparently bitten me. My google fu failed to find this thread despite many searches. Very frustrating indeed.

Running Version 1.12.0-rc3-beta18 (build: 9996)

---

<div class="post-metadata">

**Author:** ![thedug](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/thedug/32/10143_2.png) [@thedug](https://forums.docker.com/u/thedug)\
**Post date:** [July 12, 2016, 3:58am UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/10 "2016-07-12T03:58:01Z")

</div>

We just ran into the same problem.

---

<div class="post-metadata">

**Author:** ![thedug](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/thedug/32/10143_2.png) [@thedug](https://forums.docker.com/u/thedug)\
**Post date:** [July 12, 2016, 3:59am UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/11 "2016-07-12T03:59:35Z")

</div>

localhost and 127.0.0.1 are both broken for us

---

<div class="post-metadata">

**Author:** ![wilkystorm](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wilkystorm](https://forums.docker.com/u/wilkystorm)\
**Post date:** [February 27, 2018, 2:41pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/12 "2018-02-27T14:41:00Z")

</div>

Hello, I am new to Docker so I apologize in advance if this is a very remedial question but is there any way that I should be able to access a service running inside of a docker container on my mac? I have tried localhost:port, 127.0.0.1:port, the ip address of the docker container and port nothing works. I have tried with docker compose setting network: host in the yaml file and using docker client specifying -p port:port. If anyone can provide me with info on how in any way i can connect to services running in docker containers from my mac I would greatly appreciate it. Thank you!

---

<div class="post-metadata">

**Author:** ![wilkystorm](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wilkystorm](https://forums.docker.com/u/wilkystorm)\
**Post date:** [February 27, 2018, 3:32pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/13 "2018-02-27T15:32:11Z")

</div>

I have the following solution which is working for me. With docker-compose instead of network: host in docker-compose.yml, use  
ports:  
– “port:port”

---

<div class="post-metadata">

**Author:** ![sdetweil](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sdetweil](https://forums.docker.com/u/sdetweil)\
**Post date:** [February 27, 2018, 4:09pm UTC](https://forums.docker.com/t/localhost-connection-refused-with-beta9/10478/14 "2018-02-27T16:09:20Z")

</div>

because mac, like windows, needs a virtual machine to provide the correct support for docker, you need to map the container ports to the VM host ports, and then access the port thru the VM ip address.

on my mac that ip address is 169.254.175.33
