Docker Community Forums

Share and learn in the Docker community.

Localhost connection refused with beta9


(Marco Reinwarth) #1

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

Should docker run --net=host work?
Cannot access network port on host using bridge network
(Marco Reinwarth) #2

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


(Mnawalany) #3

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


(Marco Reinwarth) #4

I have no workaround, yet


(Fabrizio Di Napoli) #5

Same problem here…


(Curtisrcooley) #6

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.


(Lyleh) #7

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.


(Adyach) #8

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


(Cooperaj) #9

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)


(Douglas Ferguson) #10

We just ran into the same problem.


(Douglas Ferguson) #11

localhost and 127.0.0.1 are both broken for us


(Wilkystorm) #12

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!


(Wilkystorm) #13

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”


(Sam) #14

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