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

host.docker.internal is not resolved by nginx #259

Closed
devployment opened this issue Dec 15, 2019 · 12 comments
Closed

host.docker.internal is not resolved by nginx #259

devployment opened this issue Dec 15, 2019 · 12 comments
Labels

Comments

@devployment
Copy link

Checklist

  • Have you pulled and found the error with jc21/nginx-proxy-manager:latest docker image?
    ✔️
  • Are you sure you're not using someone else's docker image?
    ✔️

Describe the bug

host.docker.internal is not resolved by nginx

To Reproduce

Steps to reproduce the behavior:

  1. Run NPM
  2. Run some web application on the Docker host (e.g. on port 5000)
  3. Use host.docker.internal as target

image

  1. Try to access the proxied host.docker.internal:5000
  2. Target page is not displayed and error is logged
2019/12/15 19:47:17 [error] 998#998: *368 host.docker.internal could not be resolved (3: Host not found), client: 192.168.16.1, server: xxx.local.test, request: "GET / HTTP/2.0", host: "xxx.local.test", referrer: "http://localhost:81/nginx/proxy"

Expected behavior

The NPM proxied domain, should show the page running under 127.0.0.1 on the Docker host

Workaround

If I ping host.docker.internal on the running app container and use the resulting IP as target it works

image

Operating System

macOS

@devployment
Copy link
Author

Well, seems to be a general Docker issue

docker/for-mac#2965

@devployment devployment changed the title host.docker.internal is not resolved by nginx host.docker.internal is not resolved by nginx Dec 16, 2019
@Robokishan
Copy link

Robokishan commented May 29, 2021

I am still facing this issue. Any work around ?

  • already installed docker latest version.
  • extra_hosts: - "host.docker.internal:host-gateway"
  • Able to ping host.docker.internal successfully
  • nslookup works host.docker.internal successfully

But still it is not working in nginx any workaround ?

@devadattas
Copy link

Same here!

@stealthdave
Copy link

This looks to be an issue with nginx rather than the Proxy Manager. Nginx itself does not seem to use /etc/hosts as a resolver:

https://stackoverflow.com/questions/8305015/when-using-proxy-pass-can-etc-hosts-be-used-to-resolve-domain-names-instead-of/8559797#8559797

Perhaps a feature request to add dnsmasq to the container that can be enabled with an environment variable, e.g. -e "ENABLE_DNSMASQ=true", to allow the use of --add-host and/or extra_hosts in the docker setup as this is a very common use case to set up proxy servers for the docker host.

@EDIflyer
Copy link

EDIflyer commented Jul 9, 2022

Just came across this bug too (seems linked to #1225).

To confirm, when I run the following command:
docker run -it --name alpine4 --network nginx-proxy-manager_default --add-host host.docker.internal:host-gateway alpine ash

I can happily ping 172.17.0.1 as well as host.docker.internal and can also wget to the service running on the host

However when setting up an NPM proxy pointed to host.docker.internal it produces a 502 Bad Gateway openresty error. Changing the forward hostname/IP to 172.17.0.1 then works fine.

(Just to confirm this is with the following text added to the nginx proxy manager Docker compose file too, so the host should have been mapped OK at a container level.)

    extra_hosts:
      - "host.docker.internal:host-gateway"

@williamblair333
Copy link

williamblair333 commented Jul 10, 2022

Changing the forward hostname/IP to 172.17.0.1 then works fine. Would you give an example of that in a docker-compose file , or where would this change be made?

@jbald18
Copy link

jbald18 commented Jul 11, 2022

+1 ^^ @EDIflyer

@EDIflyer
Copy link

Changing the forward hostname/IP to 172.17.0.1 then works fine. Would you give an example of that in a docker-compose file , or where would this change be made?

Sorry thought I replied before - it was just in the npm proxy host...
image

@KeivanDjafarizad
Copy link

Only workaround that I found, for development environment on the same machine, is to set network_mode: host, removing the ports and then forwarding to localhost. It's not the best but considering the fact that I'm using it to resolve names for local development, works for me

version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    #ports:
    # - '80:80'
    # - '81:81'
    # - '443:443'
    network_mode: host
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt

@Ran-Xing
Copy link

@KeivanDjafarizad I also have network_mode: host ,
and curl and MySQL inside my container work fine
But nginx still doesn't resolve
How do you solve it now?

@hitesh-pathak
Copy link

Is this actually resolved? Or is there any other issue to follow?

@MobCode100
Copy link

The issue is with Docker's default DNS 127.0.0.11 because it does not include extra_hosts and --add-host entries which are stored to /etc/hosts file. When the resolver is set, nginx will not read /etc/hosts. 2 workarounds are:

  1. Change host.docker.internal to 172.17.0.1 which it's not sure whether Docker will always use the same IP.
  2. Install dnsmasq and run dnsmasq inside the container. Set nginx resolver to 127.0.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests