cloudfoundry-attic / cfdev

A fast and easy local Cloud Foundry experience on native hypervisors, powered by LinuxKit with VPNKit
Apache License 2.0
227 stars 64 forks source link

Issues connecting to Docker container running on localhost #36

Closed izgeri closed 6 years ago

izgeri commented 6 years ago

If I start a service defined in a docker compose file:

version: "2"

services:
  my_service:
    image: my_service_image
    ports:
      - 8080:80

by running docker-compose up -d my_service, I can curl -i localhost:8080 from the command line on my machine and get a response from my service as expected.

If I deploy a basic app to CF Dev (for example, see here) by running cf push and try to run

cf ssh hello-world
curl -i host.pcfdev.io:8080

the curl request hangs, and eventually dies on the error curl: (7) Failed to connect to host.pcfdev.io port 8080: Connection timed out

On my local machine, I can also run

$ nc -vz localhost 8080
found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
    outif lo0
    src 127.0.0.1 port 63891
    dst 127.0.0.1 port 8080
    rank info not available
    TCP aux info available

Connection to localhost port 8080 [tcp/http-alt] succeeded!

but from within my hello-world app running nc -vz host.pcfdev.io 8080 also hangs and eventually results in the message

nc: connect to host.pcfdev.io port 8080 (tcp) failed: Connection timed out

Running nslookup host.pcfdev.io while ssh'd into my hello-world app gives the following:

Server:     169.254.0.2
Address:    169.254.0.2#53

Name:   host.pcfdev.io
Address: 192.168.65.1

I used to be able to use the host.pcfdev.io URL like I would use localhost so that my apps running in PCF Dev could send requests to apps running in Docker containers, but this no longer seems possible with CF Dev. Is there a new URL I should be using, or is this functionality no longer supported?

sclevine commented 6 years ago

Hi @izgeri,

host.pcfdev.io should resolve to 192.168.65.2, but a bug in versions earlier than v0.0.4 had resolution configured for 192.168.65.1 by mistake. Can you upgrade to v0.0.6?

izgeri commented 6 years ago

That did the trick. Thanks @sclevine!!

sig-fisherj commented 6 years ago

I just tried to connect to a service broker outside of cf dev using: cf create-service-broker broker-name cf_user cf_pass http://host.pcfdev.io:<broker_port> and the return was:

Creating service broker broker-name as admin... FAILED Server error, status code: 504, error code: 10001, message: The request to the service broker timed out: http://host.pcfdev.io:8890/v2/catalog

What I ended up doing was the following: In window 1:

Then I used that IP instead of host.pcfdev.io in the cf create-service-broker command above and everything worked.