Cannot curl a local webserver on host from inside container

Hi, I’m running an Nginx Proxy Manager container on my ubuntu 22.04 server. I am trying to access a server that I have started with Static Web Server (not the docker version, so it runs directly on the server) from the Nginx Proxy Manager container. When I start the server on port 8080 I can successfully curl it from the host machine using a variety of callback URLs and even the 172.17.0.1:8080 and 172.18.0.1:8080 (which I think are related to docker but I am unsure fully on how it works). However no matter how I change the docker-compose file with all of the host gateway options I cannot curl it from inside the container using host.docker.internal:8080 or anything else. Below is my compose file.

version: '3.8'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    extra_hosts:
      - "host.docker.internal:172.17.0.1"

My apologies if this is a repeat I have read the other questions on the same issue but I cannot find a solution. Thanks for any help in advance :slight_smile:

Maybe you already solved it, but I found your question after deleting a spammer’s response. Instead of seting a static IP use the special alias “host-gateway”. Then it will be replaced with the gateway of the container which is the IP of the host on that network.

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

Since the gateway must be available, unless a local firewall rejects it, you should be able to access the port. Docker Compose creates a custom docker bridge and you will not know the IP of the gateway, that’s why the host-gateway alias is there. If I remember correctly, the default gateway was also available in previous Docker versions but I checked it in Docker 26.0 and didn’t work. But the host-gateway did.

Update:

I had to realize I was wrong. I forgot that I changed the default Docker network settings on the host and the IP of the default Docker network’s gateway was 172.30.0.1 and not 172.17.0.1. That’s why it didn’t work for me.

The host-gateway alias could still help if you similarly changed the default settings.

1 Like

Uh oh ! Right now I’m retrieving the gateway IP of my Docker network using docker network inspect and if I correctly understand, I didn’t need to do this. Wow ! Nice tip. Will try as soon as possible… Thanks !

If you need the default gateway IP, then yes, you don’t need to inspect the network, but I was wrong when I wrote in my original post that it would give you the gateway of the network which is used by the container.

If you want to read about it in more details, I actually have an older post from the time when I still knew what I was talking about, right after testing it :slight_smile:

Interestingly, it completely disappeared from the documentation and this keyword can be found only in the source code and some release notes…

1 Like