Docker Community Forums

Share and learn in the Docker community.

Docker OS X beta 9 - curl localhost returned error


(Schubert Anselme) #1

Docker beta 9 is not forwarding ports to localhost, I did made sure to turn on native/port-forwarding.

Expected behavior

curl localhost:8080

<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <meta name="author" content="">
    <meta name="description" content="">
    <title></title>
  </head>
  <body>
    <div class="container"></div>
    <script src=bundle.js></script>
  </body>
</html>```

### Actual behavior
```curl localhost:8080```
curl: (52) Empty reply from server

### Information

#### the output of:
```pinata diagnose -u```
OS X: version 10.11.5 (build: 15F28b)
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/20160430-100920.tar.gz
Most specific failure is: No error was detected
Your unique id is: C9DD462C-5929-4DF2-B8E7-7E935A656681
Please quote this in all correspondence.

```pinata get native/port-forwarding```
true

(Andrevtg) #2

I had to reset Docker for Mac after upgrading to beta 9. It solved the same issue. Did you try that?


(Schubert Anselme) #3

Tried reseting to default settings, uninstalled and reinstalled did not fixed it either. I’m on OS X 10.11.5 (with SIP enabled, did noticed this affecting another software I was using). docker-compose returned:

docker-compose ps

Name Command State Ports

test_web_1 npm start Up 0.0.0.0:8080->8080/tcp


(Andrevtg) #4

Did you try to check if the port is wrongly allocated to a IP inside the VM (and not the host)? To get into the VM (root/ empty pwd):

screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

Also check in your Mac what are the network settings (nat or hostnet):

pinata list

(Schubert Anselme) #5

That’s interesting, docker-compose ps returned

Name Command State Ports
-------------------------------------------------------
test_web_1 npm start Up 0.0.0.0:8080->8080/tcp

docker-compose exec web curl localhost:8080

hello|world
```

and pinata list

These are advanced configuration settings to customise Docker.app on MacOSX.
You can set them via pinata set .

:whale: hostname = docker
Hostname of the virtual machine endpoint, where container ports will be
exposed if using nat networking. Access it via ‘docker.local’.

:whale: hypervisor = native (memory=2, ncpu=4)
The Docker.app includes embedded hypervisors that run the virtual machines
that power the containers. This setting allows you to control which the
default one used for Linux is.

▸ native: a version of the xhyve hypervisor that uses the MacOSX
Hypervisor.framework to run container VMs. Parameters:
memory (VM memory in gigabytes), ncpu (vCPUs)

:whale: network = hostnet (docker-ipv4=192.168.65.2, host-ipv4=192.168.65.1)
Controls how local containers can access the external network via the
MacOS X host. This includes outbound traffic as well as publishing ports
for external access to the local containers.

▸ hostnet: a mode that helps if you are using a VPN that restricts
connectivity. Activating this mode will proxy container network
packets via the Docker.app process as host socket traffic.
Parameters: docker-ipv4 (docker node), host-ipv4 (host node)
▸ nat: a mode that uses the MacOS X vmnet.framework to route container
traffic to the host network via a NAT.

:whale: filesystem = osxfs
Controls the mode by which files from the MacOS X host and the container
filesystem are shared with each other.

▸ osxfs: a FUSE-based filesystem that bidirectionally forwards OSX
filesystem events into the container.

:whale: native/port-forwarding = true
Expose container ports on the Mac, rather than the VM

▸ true: Container ports will be exposed on the Mac
▸ false: Container ports will be exposed on the VM

:whale: daemon = run ‘pinata get daemon’ or 'pinata set daemon [@file|-]>
JSON configuration of the local Docker daemon. Configure any custom
options you need as documented in:
https://docs.docker.com/engine/reference/commandline/daemon/. Set it
directly, or a @file or - for stdin.

here’s docker-compose.yml content:

version: “2”

services:
web:
image: node:latest
command: npm start
working_dir: /usr/src/app
ports:
- 8080:8080
volumes:
- .:/usr/src/app

the interesting thing is when I run screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty, then do curl localhost:8080 I get curl: (7) Failed to connect to localhost port 8080: Connection refused


(Andrevtg) #6

This is by design, I think, at least from beta 9. The hostnet mode (default) means, as far as I know, that port binding works differently.

On my local setup what do I get working fine with similar curl testing:

MAC:
curl 127.0.0.1:port --> OK
curl mac_real_ip:port --> OK

Inside VM:
curl 127.0.0.1:port --> NOT OK (by design)
curl 192.168.65.2:port --> OK
curl 172.17.0.1:port --> OK (this is the docker0 device)

Other machines on my LAN:
curl mac_real_ip:port --> OK


(Schubert Anselme) #7

I got it working, in the end it wasn’t because of docker, the web app was bound to 127.0.0.1 (inside the container), changed the binding to 0.0.0.0 and it’s now working. Thanks for the help.