[GH-ISSUE #259] host.docker.internal is not resolved by nginx #227

Closed
opened 2026-02-26 06:31:38 +03:00 by kerem · 15 comments
Owner

Originally created by @devployment on GitHub (Dec 15, 2019).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/259

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

  4. Try to access the proxied host.docker.internal:5000

  5. 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

Originally created by @devployment on GitHub (Dec 15, 2019). Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/259 **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 <img width="1159" alt="image" src="https://user-images.githubusercontent.com/7137845/70868513-d8fe2d00-1f81-11ea-8623-d2364f2a2d88.png"> 4. Try to access the proxied `host.docker.internal:5000` 5. 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 <img width="1183" alt="image" src="https://user-images.githubusercontent.com/7137845/70868633-cd5f3600-1f82-11ea-94a3-de047596b49a.png"> **Operating System** macOS
kerem 2026-02-26 06:31:38 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@devployment commented on GitHub (Dec 16, 2019):

Well, seems to be a general Docker issue

https://github.com/docker/for-mac/issues/2965

<!-- gh-comment-id:566204552 --> @devployment commented on GitHub (Dec 16, 2019): Well, seems to be a general Docker issue https://github.com/docker/for-mac/issues/2965
Author
Owner

@Robokishan commented on GitHub (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 ?

<!-- gh-comment-id:850838774 --> @Robokishan commented on GitHub (May 29, 2021): I am still facing this issue. Any work around ? * [x] already installed docker latest version. * [x] extra_hosts: - "host.docker.internal:host-gateway" * [x] Able to ping host.docker.internal successfully * [x] nslookup works host.docker.internal successfully But still it is not working in nginx any workaround ?
Author
Owner

@devadattas commented on GitHub (Mar 21, 2022):

Same here!

<!-- gh-comment-id:1073722260 --> @devadattas commented on GitHub (Mar 21, 2022): Same here!
Author
Owner

@stealthdave commented on GitHub (May 12, 2022):

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.

<!-- gh-comment-id:1125197753 --> @stealthdave commented on GitHub (May 12, 2022): 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.
Author
Owner

@EDIflyer commented on GitHub (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"
<!-- gh-comment-id:1179583932 --> @EDIflyer commented on GitHub (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" ```
Author
Owner

@williamblair333 commented on GitHub (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?

<!-- gh-comment-id:1179827372 --> @williamblair333 commented on GitHub (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?
Author
Owner

@jbald18 commented on GitHub (Jul 11, 2022):

+1 ^^ @EDIflyer

<!-- gh-comment-id:1180341273 --> @jbald18 commented on GitHub (Jul 11, 2022): +1 ^^ @EDIflyer
Author
Owner

@EDIflyer commented on GitHub (Jul 11, 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?

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

<!-- gh-comment-id:1180361588 --> @EDIflyer commented on GitHub (Jul 11, 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? Sorry thought I replied before - it was just in the npm proxy host... ![image](https://user-images.githubusercontent.com/13610277/178266353-08504926-6d67-4b00-b2e4-6018bf3b57e4.png)
Author
Owner

@KeivanDjafarizad commented on GitHub (Sep 2, 2022):

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
<!-- gh-comment-id:1235677934 --> @KeivanDjafarizad commented on GitHub (Sep 2, 2022): 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 ```
Author
Owner

@Ran-Xing commented on GitHub (Sep 25, 2022):

@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?

<!-- gh-comment-id:1257178763 --> @Ran-Xing commented on GitHub (Sep 25, 2022): @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?
Author
Owner

@hitesh-pathak commented on GitHub (Feb 11, 2024):

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

<!-- gh-comment-id:1937576749 --> @hitesh-pathak commented on GitHub (Feb 11, 2024): Is this actually resolved? Or is there any other issue to follow?
Author
Owner

@seif2003 commented on GitHub (Jan 12, 2025):

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.

In my case, the default Docker bridge network uses 10.0.0.1, which you can confirm by running ip addr show docker0. It works fine for me with 10.0.0.1.

Also, you have to add network_mode: host in your Docker Compose file to ensure the container shares the host's network stack

<!-- gh-comment-id:2585934303 --> @seif2003 commented on GitHub (Jan 12, 2025): > 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. In my case, the default Docker bridge network uses `10.0.0.1`, which you can confirm by running `ip addr show docker0`. It works fine for me with 10.0.0.1. Also, you have to add `network_mode: host` in your Docker Compose file to ensure the container shares the host's network stack
Author
Owner

@JoshMcCullough commented on GitHub (Jan 24, 2025):

Changing the forward hostname/IP to 172.17.0.1 then works fine.

Doesn't the proper IP to use depend on your Docker network config, though?

<!-- gh-comment-id:2612779742 --> @JoshMcCullough commented on GitHub (Jan 24, 2025): > Changing the forward hostname/IP to `172.17.0.1` then works fine. Doesn't the proper IP to use depend on your Docker network config, though?
Author
Owner

@EDIflyer commented on GitHub (Jan 24, 2025):

Changing the forward hostname/IP to 172.17.0.1 then works fine.

Doesn't the proper IP to use depend on your Docker network config, though?

Yes, but I've allocated a fixed IP to NPM so it doesn't keep changing.

<!-- gh-comment-id:2613483322 --> @EDIflyer commented on GitHub (Jan 24, 2025): > > Changing the forward hostname/IP to `172.17.0.1` then works fine. > > Doesn't the proper IP to use depend on your Docker network config, though? Yes, but I've allocated a fixed IP to NPM so it doesn't keep changing.
Author
Owner

@auxym commented on GitHub (Mar 12, 2025):

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

#1225 is open and is tracking the same issue, from what I understand

<!-- gh-comment-id:2716009707 --> @auxym commented on GitHub (Mar 12, 2025): > Is this actually resolved? Or is there any other issue to follow? #1225 is open and is tracking the same issue, from what I understand
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-proxy-manager-NginxProxyManager#227
No description provided.