Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to docker host from within a container #37

Closed
toddlucas opened this issue Aug 13, 2016 · 12 comments
Closed

Unable to connect to docker host from within a container #37

toddlucas opened this issue Aug 13, 2016 · 12 comments

Comments

@toddlucas
Copy link

Expected behavior

I would like to connect my dockerized app to ports on my local host, to use development databases, etc.

Actual behavior

I am unable to make any connection to the docker host, either using the container's IP or the gateway IP (e.g. 172.17.0.1).

Information

Docker version 1.12.0, build 8eab29e

I also attempted to create a dedicated bridge subnet using docker network so that I could assign an IP to the container, but I experienced the same results.

I tested using an HTTP server on my host (ASP.NET Core Kestrel server), on the wildcard IP 0.0.0.0 at port 5000, attempting connection with curl. I also tested with Postgres, updating pg_hba.conf with both the wildcard IP and the DockerNAT IP (10.0.75.1 in my case).

Any workarounds would be appreciated.

Steps to reproduce the behavior

  1. Create a containerized app (I tried several, but ended up doing most testing with a vanilla Ubuntu image).
  2. Expose a service on the host at a specific port (like Postgres on port 5432), ensuring that the listener is listening on the correct IP.
  3. Attempt to connect to the port using the container's IP or gateway IP.
  4. Should see connection refused

Thanks!

@dgageot
Copy link
Member

dgageot commented Sep 1, 2016

Hi @toddlucas thank you for reporting this issue. Your use case is common to a lot of users and we are currently trying to find the best way to solve it. However I don't know if/when this will happen yet.

@ecsousa
Copy link

ecsousa commented Sep 11, 2016

Hi,

I've was able to connect doing a working arround with ngix by starting it with the following config

stream {
    server {
        listen 10.0.75.1:2375;
        proxy_pass 127.0.0.1:2375;
    }
}

Then, on container I just set DOCKER_HOST variable to 10.0.75.1.

NOTE: My Docker toolbox internal virtual switch subnet address is set to 10.0.75.0 (default), that's why I've used 10.0.75.1 IP address

@vandammeb
Copy link

Any update on this issue?
@ecsousa : I tried the workaround with the nginx proxy, but could not get that working (nginx would not bind to the specified ip). Is it possible to post your complete nginx config and your docker(-compose) file?

@ecsousa
Copy link

ecsousa commented Sep 22, 2016

@vandammeb Here's my nginx config file.

nginx.conf.txt

Note that, if you have changed the subnet address on network config, you will have to change the listen address on nginx config.

Also, remember to specify -e DOCKER_HOST=10.0.75.1 (or your host IP) when you are creating your container, to make sure docker client will try to connect to correct server

I am using the following PowerShell command to find out the correct IP address when creating my container. It should return you the right IP address you should use to replace 10.0.75.1 (on both container creation command line, and nginx file):

(Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex (Get-NetAdapter | ? {$_.Name -like '*(DockerNAT)*' }).InterfaceIndex).IPAddress

@vandammeb
Copy link

@ecsousa Still no luck with the workaround you suggested. The same nginx bind issue persists:

nginx_1 | 2016/10/10 16:41:17 [emerg] 1#1: bind() to 10.0.75.1:9003 failed (99: Cannot assign requested address)

Would you mind having a look at my stackoverflow question?
My docker-compose file and network info are available there.

@vandammeb
Copy link

@dgageot Any chance this issues has been addressed in the current beta? (i'm using the stable version)

@jasonbivins
Copy link

closing this one - it has been resolved in https://github.com/docker/pinata/issues/4026

@toddlucas
Copy link
Author

Hi @jasonbivins , I'm not able to see this repo or issue. Can you give us more details on when and where we might see this fix? Thanks!

@jasonbivins
Copy link

Hi @toddlucas Apologies, but that is actually our internal repo

The issue is listed as fixed in 17.06 but I don't see a specific item for it in the release notes. I'll reopen this issue until I can confirm for sure that this was included.

@jasonbivins jasonbivins reopened this Jun 5, 2017
@jasonbivins
Copy link

Hi @toddlucas I was able to confirm that this feature has been added in the latest Edge channel build.
Two DNS entries were created - each for their respective OS
docker.for.mac.localhost
docker.for.win.localhost

I ran a few quick tests and was able to telnet to docker.for.win.localhost from inside a container.

Thanks!
Jason

@toddlucas
Copy link
Author

Hi @jasonbivins , thanks for following up. That's great news. Feel free to close.

@docker-robott
Copy link
Collaborator

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked

@docker docker locked and limited conversation to collaborators Jun 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants